Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {
- ApplicationCommandType,
- ApplicationCommandOptionType,
- EmbedBuilder,
- ChannelType,
- } = require('discord.js');
- const logSchema = require(`${process.cwd()}/src/database/LogChannel.js`);
- module.exports = {
- name: 'setup-logs',
- description: 'Setup and manage the logging system for your server.',
- usage: '/setup-logs <enable/disable> [channelId]',
- category: 'Admin',
- userPerms: ['ManageChannels'],
- botPerms: [],
- cooldown: 5,
- guildOnly: false,
- options: [
- {
- name: 'enable',
- description: 'Enable the logging system and set the log channel.',
- type: ApplicationCommandOptionType.Subcommand,
- options: [
- {
- name: 'channelid',
- description: 'The ID of the channel to set as the log channel.',
- type: ApplicationCommandOptionType.String,
- required: true,
- },
- ],
- },
- {
- name: 'disable',
- description: 'Disable the logging system.',
- type: ApplicationCommandOptionType.Subcommand,
- },
- ],
- run: async (client, interaction) => {
- const subCommand = interaction.options.getSubcommand();
- const guildId = interaction.guildId;
- try {
- switch (subCommand) {
- case 'enable': {
- const channelId = interaction.options.getString('channelid');
- const channel = await client.channels.fetch(channelId);
- if (!channel || (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.GuildVoice)) {
- const errorEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({
- name: 'Error 🚫',
- iconURL: client.user.displayAvatarURL(),
- })
- .setDescription('You must specify a valid text or voice channel to set as the log channel.')
- .setFooter({
- text: 'CubeCloud Logging',
- iconURL: client.user.displayAvatarURL(),
- });
- return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
- }
- await logSchema.findOneAndUpdate(
- { Guild: guildId },
- {
- Channel: channel.id,
- Events: [
- "MESSAGE_DELETE",
- "MESSAGE_EDIT",
- "PROFILE_PICTURE_UPDATE",
- "VOICE_CHANNEL_JOIN",
- "VOICE_CHANNEL_LEAVE",
- "USER_BAN",
- "USER_UNBAN",
- "ROLE_CREATE",
- "ROLE_DELETE",
- "CHANNEL_CREATE",
- "CHANNEL_DELETE",
- ],
- CreatedAt: new Date(),
- },
- { upsert: true }
- );
- const enableEmbed = new EmbedBuilder()
- .setColor('#0000FF')
- .setAuthor({
- name: 'Logging System Enabled ✅',
- iconURL: client.user.displayAvatarURL(),
- })
- .setDescription(`Logging system has been enabled and set to <#${channel.id}>.`)
- .setFooter({
- text: 'CubeCloud Logging',
- iconURL: client.user.displayAvatarURL(),
- });
- return interaction.reply({ embeds: [enableEmbed] });
- }
- case 'disable': {
- await logSchema.findOneAndUpdate(
- { Guild: guildId },
- { $unset: { Channel: "" }, $set: { Events: [], loggingEnabled: false } }
- );
- const disableEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({
- name: 'Logging System Disabled ❌',
- iconURL: client.user.displayAvatarURL(),
- })
- .setDescription('Logging system has been disabled.')
- .setFooter({
- text: 'CubeCloud Logging',
- iconURL: client.user.displayAvatarURL(),
- });
- return interaction.reply({ embeds: [disableEmbed] });
- }
- default: {
- const invalidEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({
- name: 'Error 🚫',
- iconURL: client.user.displayAvatarURL(),
- })
- .setDescription('Invalid subcommand.')
- .setFooter({
- text: 'CubeCloud Logging',
- iconURL: client.user.displayAvatarURL(),
- });
- return interaction.reply({ embeds: [invalidEmbed], ephemeral: true });
- }
- }
- } catch (error) {
- console.error(error);
- const errorEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({
- name: 'Error 🚫',
- iconURL: client.user.displayAvatarURL(),
- })
- .setDescription('An error occurred while processing the command.')
- .setFooter({
- text: 'CubeCloud Logging',
- iconURL: client.user.displayAvatarURL(),
- });
- return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
- }
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement