//---- schema const { Schema, model } = require('mongoose') const errSchema = new Schema({ Guild: String, Channel: String }) module.exports = model('errSchema', errSchema) //---- event const { Interaction, EmbedBuilder } = require("discord.js"); const errorLog = require("../models/errorlog"); module.exports = { name: "interactionCreate", async execute(interaction, client) { if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; try { await command.execute(interaction, client); } catch (err) { console.log(err) const data = errorLog.findOne({ Guild: interaction.guild.id }); if (!data) return; if (data){ const ch = await client.channels.cache.get(data.Channel); const errorembed = new EmbedBuilder() .setTitle(`❗Error Detected❗`) .setDescription(`\`\`\`${err}\`\`\``) .setTimestamp() .setFooter({ text: `Please contact my creator: CYUKIZZZ#0404` }); await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true, }); await ch.send({ embeds: [errorembed] }) } } }, }; //---- command const { SlashCommandBuilder, EmbedBuilder, PermissionsBitField, Embed, } = require("discord.js"); const errorSchema = require("../../models/errorlog"); const colors = require('../../colors.json') module.exports = { data: new SlashCommandBuilder() .setName("error-logs") .setDescription("Configure the error-logs system") .addSubcommand((command) => command .setName("set") .setDescription("Set up the error-logs system") .addChannelOption((option) => option .setName("channel") .setDescription( "The channel you want to set as your error-logs channel" ) .setRequired(true) ) ) .addSubcommand((command) => command.setName("disable").setDescription("Disables the error-logs system") ), async execute(interaction, client) { const sub = interaction.options.getSubcommand(); switch (sub) { case "set": try { const permissions = "Administrator"; if ( !interaction.member.permissions.has( PermissionsBitField.Flags.Administrator ) ) { const modembed = new EmbedBuilder() .setDescription( "❌ You **do not** have permissions to run this command! ❌" ) .setTimestamp() .setFooter({ text: `Permissions needed: ${permissions}` }) .setImage( "https://cdn.discordapp.com/attachments/847184918878224447/1114162959183249488/Stop_hand.svg.png" ) .setColor("Red"); return await interaction.reply({ embeds: [modembed] }); } const loadembed = new EmbedBuilder() .setDescription(`⏳ Setting up the error-logs system...`) .setColor(colors.config); await interaction.reply({ embeds: [loadembed] }); const { channel, options, guildId } = interaction; const welChannel = options.getChannel("channel"); const data = await errorSchema.findOne({ Guild: guildId }); if (!data) { await errorSchema.create({ Guild: guildId, Channel: welChannel.id, }); const embed = new EmbedBuilder() .setColor(colors.config) .setThumbnail(interaction.guild.iconURL()) .setDescription( `✔ Success!\n➥ Your error-logs channel has been set to ${welChannel}!` ); await interaction.editReply({ embeds: [embed] }); } else if (data) { const ch = client.channels.cache.get(data.Channel); const embedss = new EmbedBuilder() .setColor(colors.cant) .setDescription( `\`❗Your error-logs channel has already been set to\` ${ch}` ) .setTimestamp() await interaction.editReply({ embeds: [embedss] }); } } catch (err) { console.log(err); } break; case "disable": if ( !interaction.member.permissions.has( PermissionsBitField.Flags.Administrator ) ) { const modembed = new EmbedBuilder() .setDescription( "❌ You **do not** have permissions to run this command! ❌" ) .setTimestamp() .setFooter({ text: `Permissions needed: ${permissions}` }) .setImage( "https://cdn.discordapp.com/attachments/847184918878224447/1114162959183249488/Stop_hand.svg.png" ) .setColor("Red"); return await interaction.reply({ embeds: [modembed] }); } const loadembed = new EmbedBuilder() .setDescription(`⏳ Disabling the error-logs system...`) .setColor(colors.config); await interaction.reply({ embeds: [loadembed] }); const { guildId } = interaction; const data = await errorSchema.findOne({ Guild: guildId, }); if (!data) { const nod = new EmbedBuilder() .setColor(colors.cant) .setDescription(`❗ \`The error-logs system was already disabled!\``) .setTimestamp() await interaction.editReply({ embeds: [nod] }) } else { if (data) { const embed = new EmbedBuilder() .setColor(colors.config) .setThumbnail(interaction.guild.iconURL()) .setDescription( `✔ Success!\n➥ Your error-logs system has been successfully disabled!` ) .setTimestamp(); await interaction.editReply({ embeds: [embed] }); await errorSchema.deleteMany({ Guild: guildId}) } } } }, };