diff --git a/commands/interactions/ask.js b/commands/interactions/ask.js index 92ef7a3..5f7c83f 100644 --- a/commands/interactions/ask.js +++ b/commands/interactions/ask.js @@ -121,7 +121,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); @@ -133,7 +133,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); diff --git a/commands/interactions/imagine.js b/commands/interactions/imagine.js index 32a66ba..bb558c4 100644 --- a/commands/interactions/imagine.js +++ b/commands/interactions/imagine.js @@ -110,7 +110,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); @@ -122,7 +122,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); diff --git a/commands/interactions/optimize.js b/commands/interactions/optimize.js index 3a936b2..d7f1f0f 100644 --- a/commands/interactions/optimize.js +++ b/commands/interactions/optimize.js @@ -108,7 +108,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); @@ -120,7 +120,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); diff --git a/commands/interactions/translate.js b/commands/interactions/translate.js index 4ddb9ad..5e9d444 100644 --- a/commands/interactions/translate.js +++ b/commands/interactions/translate.js @@ -113,7 +113,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); @@ -125,7 +125,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: interaction.user.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await interaction.editReply({ embeds: [embed] }).catch(() => null); diff --git a/commands/messages/ask-gpt 3.5.js b/commands/messages/ask-gpt 3.5.js index e6a176e..32378a0 100644 --- a/commands/messages/ask-gpt 3.5.js +++ b/commands/messages/ask-gpt 3.5.js @@ -97,7 +97,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await message.reply({ embeds: [embed] }).catch(() => null); @@ -109,7 +109,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await message.reply({ embeds: [embed] }).catch(() => null); diff --git a/commands/messages/ask-gpt 4.js b/commands/messages/ask-gpt 4.js index 8a7aef0..093b1f1 100644 --- a/commands/messages/ask-gpt 4.js +++ b/commands/messages/ask-gpt 4.js @@ -97,7 +97,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await message.reply({ embeds: [embed] }).catch(() => null); @@ -109,7 +109,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await message.reply({ embeds: [embed] }).catch(() => null); diff --git a/commands/messages/imagine.js b/commands/messages/imagine.js index a769955..a64e688 100644 --- a/commands/messages/imagine.js +++ b/commands/messages/imagine.js @@ -100,7 +100,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await message.reply({ embeds: [embed] }).catch(() => null); @@ -112,7 +112,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await message.reply({ embeds: [embed] }).catch(() => null); diff --git a/commands/messages/optimize.js b/commands/messages/optimize.js index 5fb6333..70609ec 100644 --- a/commands/messages/optimize.js +++ b/commands/messages/optimize.js @@ -86,7 +86,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await message.reply({ embeds: [embed] }).catch(() => null); @@ -98,7 +98,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await message.reply({ embeds: [embed] }).catch(() => null); diff --git a/commands/messages/translate.js b/commands/messages/translate.js index 6219ef8..72f463c 100644 --- a/commands/messages/translate.js +++ b/commands/messages/translate.js @@ -99,7 +99,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.response.error.message); + .setDescription(error.response.error.message.length > 4096 ? error.response.error.message.substring(0, 4093) + "..." : error.response.error.message); await message.reply({ embeds: [embed] }).catch(() => null); @@ -111,7 +111,7 @@ module.exports = { name: question.length > 256 ? question.substring(0, 253) + "..." : question, iconURL: message.author.displayAvatarURL() }) - .setDescription(error.message); + .setDescription(error.message.length > 4096 ? error.message.substring(0, 4093) + "..." : error.message); await message.reply({ embeds: [embed] }).catch(() => null); diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 4c6cc2f..bd7dd7c 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -5,664 +5,670 @@ const { moderation } = require('../configs/moderation'); module.exports = async (client, interaction) => { - // Command Handler - if (interaction.isChatInputCommand()) { + try { - const command = client.SlashCommands.get(interaction.commandName); - if (command) { + // Command Handler + if (interaction.isChatInputCommand()) { + + const command = client.SlashCommands.get(interaction.commandName); + if (command) { + + try { + command.execute(client, interaction); + } catch (error) { + console.error(chalk.bold.redBright(error)); + return await interaction.reply({ content: error.message.length > 4096 ? error.message.slice(0, 4093) + "..." : error.message, ephemeral: true }).catch(() => null); + }; - try { - command.execute(client, interaction); - } catch (error) { - console.error(chalk.bold.redBright(error)); - return await interaction.reply({ content: error.message.length > 4096 ? error.message.slice(0, 4093) + "..." : error.message, ephemeral: true }).catch(() => null); }; - }; + // Auto Moderation + } else if (interaction.isButton()) { - // Auto Moderation - } else if (interaction.isButton()) { + const id = interaction.customId.split('-'); - const id = interaction.customId.split('-'); + if (['deleteMessage', 'timeout', 'kick', 'ban'].includes(id[0])) { - if (['deleteMessage', 'timeout', 'kick', 'ban'].includes(id[0])) { + await interaction.deferReply({ ephemeral: true }); - await interaction.deferReply({ ephemeral: true }); + let admin = false; + if ( + interaction.member.roles.cache.hasAny(...moderation.AdminRoles) + || moderation.AdminUsers.includes(interaction.member.id) + ) admin = true; - let admin = false; - if ( - interaction.member.roles.cache.hasAny(...moderation.AdminRoles) - || moderation.AdminUsers.includes(interaction.member.id) - ) admin = true; + if (id[0] === 'deleteMessage') { - if (id[0] === 'deleteMessage') { + const channel = client.channels.cache.get(id[1]); + if (admin || channel?.permissionsFor(interaction.member).has('ManageMessages')) { - const channel = client.channels.cache.get(id[1]); - if (admin || channel?.permissionsFor(interaction.member).has('ManageMessages')) { + if (channel.permissionsFor(interaction.guild.members.me).has('ManageMessages')) { - if (channel.permissionsFor(interaction.guild.members.me).has('ManageMessages')) { + const message = await channel.messages.fetch({ message: id[2] }).catch(() => null); + if (message) { - const message = await channel.messages.fetch({ message: id[2] }).catch(() => null); - if (message) { + try { - try { + await message.delete(); - await message.delete(); + if (interaction.message.components.length === 1) { - if (interaction.message.components.length === 1) { + const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); - const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); + embed.addFields({ + name: 'Message Action:', + value: `Message deleted by ${interaction.user} \`(${interaction.user.id})\`` + }); - embed.addFields({ - name: 'Message Action:', - value: `Message deleted by ${interaction.user} \`(${interaction.user.id})\`` - }); + const row1 = Discord.ActionRowBuilder.from(interaction.message.components[0]); - const row1 = Discord.ActionRowBuilder.from(interaction.message.components[0]); + const buttons = []; + for (const button of interaction.message.components[1].components) { + const newButton = Discord.ButtonBuilder.from(button).setDisabled(); + buttons.push(newButton); + }; - const buttons = []; - for (const button of interaction.message.components[1].components) { - const newButton = Discord.ButtonBuilder.from(button).setDisabled(); - buttons.push(newButton); - }; + const row2 = new Discord.ActionRowBuilder() + .addComponents(buttons); - const row2 = new Discord.ActionRowBuilder() - .addComponents(buttons); + await interaction.message.edit({ + embeds: [embed], + components: [row1, row2] + }); - await interaction.message.edit({ - embeds: [embed], - components: [row1, row2] - }); + } else if (interaction.message.components.length > 1) { - } else if (interaction.message.components.length > 1) { + const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); - const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); + embed.addFields({ + name: 'Message Action:', + value: `Message deleted by ${interaction.user} \`(${interaction.user.id})\`` + }); - embed.addFields({ - name: 'Message Action:', - value: `Message deleted by ${interaction.user} \`(${interaction.user.id})\`` - }); + const row1 = Discord.ActionRowBuilder.from(interaction.message.components[0]); + + const buttons = []; + for (const button of interaction.message.components[1].components) { + const newButton = Discord.ButtonBuilder.from(button).setDisabled(); + buttons.push(newButton); + }; - const row1 = Discord.ActionRowBuilder.from(interaction.message.components[0]); + const row2 = new Discord.ActionRowBuilder() + .addComponents(buttons); + + await interaction.message.edit({ + embeds: [embed], + components: [row1, row2] + }); - const buttons = []; - for (const button of interaction.message.components[1].components) { - const newButton = Discord.ButtonBuilder.from(button).setDisabled(); - buttons.push(newButton); }; - const row2 = new Discord.ActionRowBuilder() - .addComponents(buttons); + await interaction.editReply({ content: 'The message has been deleted successfully.' }); - await interaction.message.edit({ - embeds: [embed], - components: [row1, row2] - }); + } catch (error) { + await interaction.editReply({ content: `There was an error while deleting this message, *(${error.message})*` }); + }; + } else { + + const row1 = Discord.ActionRowBuilder.from(interaction.message.components[0]); + + const buttons = []; + for (const button of interaction.message.components[1].components) { + const newButton = Discord.ButtonBuilder.from(button).setDisabled(); + buttons.push(newButton); }; - await interaction.editReply({ content: 'The message has been deleted successfully.' }); + const row2 = new Discord.ActionRowBuilder() + .addComponents(buttons); + + await interaction.message.edit({ components: [row1, row2] }); + + await interaction.editReply({ content: 'This message has already been deleted.' }); - } catch (error) { - await interaction.editReply({ content: `There was an error while deleting this message, *(${error.message})*` }); }; - } else { + } else await interaction.editReply({ content: `I need Manage Message permission in ${channel}.` }); - const row1 = Discord.ActionRowBuilder.from(interaction.message.components[0]); + } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); - const buttons = []; - for (const button of interaction.message.components[1].components) { - const newButton = Discord.ButtonBuilder.from(button).setDisabled(); - buttons.push(newButton); - }; + } else if (id[0] === 'timeout') { - const row2 = new Discord.ActionRowBuilder() - .addComponents(buttons); + if (admin || interaction.member.permissions.has('ModerateMembers')) { - await interaction.message.edit({ components: [row1, row2] }); + const member = await interaction.guild.members.fetch(id[1]).catch(() => null); + if (member) { - await interaction.editReply({ content: 'This message has already been deleted.' }); + try { - }; + if (member.moderatable) { + + if ( + interaction.member.roles.highest.comparePositionTo(member.roles.highest) <= 0 + && interaction.user.id !== interaction.guild.ownerId + ) return await interaction.editReply({ content: `You can't timeout ${member.user.tag}` }); + + const timeoutButton1 = new Discord.ButtonBuilder() + .setLabel(`60 Seconds`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('60s'); + const timeoutButton2 = new Discord.ButtonBuilder() + .setLabel(`5 Mins`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('5m'); + const timeoutButton3 = new Discord.ButtonBuilder() + .setLabel(`10 Mins`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('10m'); + const timeoutButton4 = new Discord.ButtonBuilder() + .setLabel(`1 Hour`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('1h'); + const timeoutButton5 = new Discord.ButtonBuilder() + .setLabel(`1 Day`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('1d'); + const timeoutButton6 = new Discord.ButtonBuilder() + .setLabel(`3 Days`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('3d'); + const timeoutButton7 = new Discord.ButtonBuilder() + .setLabel(`1 Week`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('1w'); + + const cancelButton = new Discord.ButtonBuilder() + .setLabel(`Cancel`) + .setStyle(Discord.ButtonStyle.Secondary) + .setCustomId('Cancel'); + + const row1 = new Discord.ActionRowBuilder() + .addComponents([ + timeoutButton1, + timeoutButton2, + timeoutButton3, + timeoutButton4, + ]); - } else await interaction.editReply({ content: `I need Manage Message permission in ${channel}.` }); - - } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); - - } else if (id[0] === 'timeout') { - - if (admin || interaction.member.permissions.has('ModerateMembers')) { - - const member = await interaction.guild.members.fetch(id[1]).catch(() => null); - if (member) { - - try { - - if (member.moderatable) { - - if ( - interaction.member.roles.highest.comparePositionTo(member.roles.highest) <= 0 - && interaction.user.id !== interaction.guild.ownerId - ) return await interaction.editReply({ content: `You can't timeout ${member.user.tag}` }); - - const timeoutButton1 = new Discord.ButtonBuilder() - .setLabel(`60 Seconds`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('60s'); - const timeoutButton2 = new Discord.ButtonBuilder() - .setLabel(`5 Mins`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('5m'); - const timeoutButton3 = new Discord.ButtonBuilder() - .setLabel(`10 Mins`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('10m'); - const timeoutButton4 = new Discord.ButtonBuilder() - .setLabel(`1 Hour`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('1h'); - const timeoutButton5 = new Discord.ButtonBuilder() - .setLabel(`1 Day`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('1d'); - const timeoutButton6 = new Discord.ButtonBuilder() - .setLabel(`3 Days`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('3d'); - const timeoutButton7 = new Discord.ButtonBuilder() - .setLabel(`1 Week`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('1w'); - - const cancelButton = new Discord.ButtonBuilder() - .setLabel(`Cancel`) - .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId('Cancel'); - - const row1 = new Discord.ActionRowBuilder() - .addComponents([ - timeoutButton1, - timeoutButton2, - timeoutButton3, - timeoutButton4, - ]); + const row2 = new Discord.ActionRowBuilder() + .addComponents([ + timeoutButton5, + timeoutButton6, + timeoutButton7, + cancelButton, + ]); + + const reply = await interaction.editReply({ + content: `Are you sure you want timeout ${member} (${member.user.tag}) if yes select one of the Timeout Durations buttons (Red ones)`, + components: [ + row1, + row2 + ] + }); - const row2 = new Discord.ActionRowBuilder() - .addComponents([ - timeoutButton5, - timeoutButton6, - timeoutButton7, - cancelButton, - ]); + const collector = await reply.createMessageComponentCollector({ time: 60000 }); - const reply = await interaction.editReply({ - content: `Are you sure you want timeout ${member} (${member.user.tag}) if yes select one of the Timeout Durations buttons (Red ones)`, - components: [ - row1, - row2 - ] - }); + collector.on('collect', async (int) => { - const collector = await reply.createMessageComponentCollector({ time: 60000 }); + if (int.customId === 'Cancel') { - collector.on('collect', async (int) => { + await collector.stop("messageDelete"); + await int.deferUpdate(); + await interaction.deleteReply(); - if (int.customId === 'Cancel') { + } else { - await collector.stop("messageDelete"); - await int.deferUpdate(); - await interaction.deleteReply(); + await collector.stop("timed out"); + await int.deferUpdate(); - } else { + const duration = ms(int.customId); + await member.timeout(duration, `Timed out by ${interaction.user.tag}`); - await collector.stop("timed out"); - await int.deferUpdate(); + const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); - const duration = ms(int.customId); - await member.timeout(duration, `Timed out by ${interaction.user.tag}`); + embed.addFields({ + name: 'Punish Action:', + value: `${member.user.tag} timed out by ${interaction.user} \`(${interaction.user.id})\` for ${ms(duration, { long: true })}.` + }); - const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); + await interaction.message.edit({ embeds: [embed] }).catch(() => null); - embed.addFields({ - name: 'Punish Action:', - value: `${member.user.tag} timed out by ${interaction.user} \`(${interaction.user.id})\` for ${ms(duration, { long: true })}.` - }); + await interaction.editReply({ + content: `${member.user.tag} has been timed out successfully.`, + components: [] + }); + + }; + + }); + + collector.on('end', async (collection, reason) => { - await interaction.message.edit({ embeds: [embed] }).catch(() => null); + if (["messageDelete", "timed out"].includes(reason)) return; await interaction.editReply({ - content: `${member.user.tag} has been timed out successfully.`, - components: [] + components: [ + new Discord.ActionRowBuilder().addComponents([ + timeoutButton1.setDisabled(true), + timeoutButton2.setDisabled(true), + timeoutButton3.setDisabled(true), + timeoutButton4.setDisabled(true) + ]), + new Discord.ActionRowBuilder().addComponents([ + timeoutButton5.setDisabled(true), + timeoutButton6.setDisabled(true), + timeoutButton7.setDisabled(true), + cancelButton.setDisabled(true) + ]), + ] }); - }; + }); - }); + } else await interaction.editReply({ content: `I can't timeout ${member.user.tag}.` }); - collector.on('end', async (collection, reason) => { + } catch (error) { + await interaction.editReply({ content: `There was an error while timeouting ${member}, *(${error.message})*` }); + }; - if (["messageDelete", "timed out"].includes(reason)) return; + } else { - await interaction.editReply({ - components: [ - new Discord.ActionRowBuilder().addComponents([ - timeoutButton1.setDisabled(true), - timeoutButton2.setDisabled(true), - timeoutButton3.setDisabled(true), - timeoutButton4.setDisabled(true) - ]), - new Discord.ActionRowBuilder().addComponents([ - timeoutButton5.setDisabled(true), - timeoutButton6.setDisabled(true), - timeoutButton7.setDisabled(true), - cancelButton.setDisabled(true) - ]), - ] - }); + const user = await client.users.fetch(id[1]).catch(() => null); + if (user) await interaction.editReply({ content: `${user.tag} is no longer in the server.` }); + else await interaction.editReply({ content: 'This user is no longer in the server.' }); - }); + }; - } else await interaction.editReply({ content: `I can't timeout ${member.user.tag}.` }); + } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); - } catch (error) { - await interaction.editReply({ content: `There was an error while timeouting ${member}, *(${error.message})*` }); - }; + } else if (id[0] === 'kick') { - } else { + if (admin || interaction.member.permissions.has('KickMembers')) { - const user = await client.users.fetch(id[1]).catch(() => null); - if (user) await interaction.editReply({ content: `${user.tag} is no longer in the server.` }); - else await interaction.editReply({ content: 'This user is no longer in the server.' }); + const member = await interaction.guild.members.fetch(id[1]).catch(() => null); + if (member) { - }; + try { - } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); + if (member.kickable) { - } else if (id[0] === 'kick') { + if ( + interaction.member.roles.highest.comparePositionTo(member.roles.highest) <= 0 + && interaction.user.id !== interaction.guild.ownerId + ) return await interaction.editReply({ content: `You can't kick ${member.user.tag}` }); - if (admin || interaction.member.permissions.has('KickMembers')) { + const kickButton = new Discord.ButtonBuilder() + .setLabel(`Kick ${member.user.username}`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('Kick'); - const member = await interaction.guild.members.fetch(id[1]).catch(() => null); - if (member) { + const cancelButton = new Discord.ButtonBuilder() + .setLabel(`Cancel`) + .setStyle(Discord.ButtonStyle.Secondary) + .setCustomId('Cancel'); - try { + const row = new Discord.ActionRowBuilder() + .addComponents([kickButton, cancelButton]); - if (member.kickable) { + const reply = await interaction.editReply({ + content: `Are you sure you want kick ${member} (${member.user.tag})`, + components: [row] + }); - if ( - interaction.member.roles.highest.comparePositionTo(member.roles.highest) <= 0 - && interaction.user.id !== interaction.guild.ownerId - ) return await interaction.editReply({ content: `You can't kick ${member.user.tag}` }); + const collector = await reply.createMessageComponentCollector({ time: 60000 }); - const kickButton = new Discord.ButtonBuilder() - .setLabel(`Kick ${member.user.username}`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('Kick'); + collector.on('collect', async (int) => { - const cancelButton = new Discord.ButtonBuilder() - .setLabel(`Cancel`) - .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId('Cancel'); + if (int.customId === 'Kick') { - const row = new Discord.ActionRowBuilder() - .addComponents([kickButton, cancelButton]); + await collector.stop("kicked"); + await int.deferUpdate(); - const reply = await interaction.editReply({ - content: `Are you sure you want kick ${member} (${member.user.tag})`, - components: [row] - }); + await member.kick(`Kicked by ${interaction.user.tag}`); - const collector = await reply.createMessageComponentCollector({ time: 60000 }); + const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); - collector.on('collect', async (int) => { + embed.addFields({ + name: 'Punish Action:', + value: `${member.user.tag} kicked by ${interaction.user} \`(${interaction.user.id})\`` + }); - if (int.customId === 'Kick') { + await interaction.message.edit({ embeds: [embed] }).catch(() => null); - await collector.stop("kicked"); - await int.deferUpdate(); + await interaction.editReply({ + content: `${member.user.tag} has been kicked successfully.`, + components: [] + }); - await member.kick(`Kicked by ${interaction.user.tag}`); + } else if (int.customId === 'Cancel') { - const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); + await collector.stop("messageDelete"); + await int.deferUpdate(); + await interaction.deleteReply(); - embed.addFields({ - name: 'Punish Action:', - value: `${member.user.tag} kicked by ${interaction.user} \`(${interaction.user.id})\`` - }); + }; + + }); - await interaction.message.edit({ embeds: [embed] }).catch(() => null); + collector.on('end', async (collection, reason) => { + + if (["messageDelete", "kicked"].includes(reason)) return; await interaction.editReply({ - content: `${member.user.tag} has been kicked successfully.`, - components: [] + components: [new Discord.ActionRowBuilder().addComponents([ + kickButton.setDisabled(true), + cancelButton.setDisabled(true) + ])] }); - } else if (int.customId === 'Cancel') { + }); - await collector.stop("messageDelete"); - await int.deferUpdate(); - await interaction.deleteReply(); + } else await interaction.editReply({ content: `I can't kick ${member.user.tag}.` }); - }; + } catch (error) { + await interaction.editReply({ content: `There was an error while kicking ${member}, *(${error.message})*` }); + }; - }); + } else { - collector.on('end', async (collection, reason) => { + const user = await client.users.fetch(id[1]).catch(() => null); + if (user) await interaction.editReply({ content: `${user.tag} is no longer in the server.` }); + else await interaction.editReply({ content: 'This user is no longer in the server.' }); - if (["messageDelete", "kicked"].includes(reason)) return; + }; - await interaction.editReply({ - components: [new Discord.ActionRowBuilder().addComponents([ - kickButton.setDisabled(true), - cancelButton.setDisabled(true) - ])] - }); + } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); - }); + } else if (id[0] === 'ban') { - } else await interaction.editReply({ content: `I can't kick ${member.user.tag}.` }); + if (admin || interaction.member.permissions.has('BanMembers')) { - } catch (error) { - await interaction.editReply({ content: `There was an error while kicking ${member}, *(${error.message})*` }); - }; + const member = await interaction.guild.members.fetch(id[1]).catch(() => null); + if (member) { - } else { - - const user = await client.users.fetch(id[1]).catch(() => null); - if (user) await interaction.editReply({ content: `${user.tag} is no longer in the server.` }); - else await interaction.editReply({ content: 'This user is no longer in the server.' }); - - }; - - } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); - - } else if (id[0] === 'ban') { - - if (admin || interaction.member.permissions.has('BanMembers')) { - - const member = await interaction.guild.members.fetch(id[1]).catch(() => null); - if (member) { - - try { - - if (member.bannable) { - - if ( - interaction.member.roles.highest.comparePositionTo(member.roles.highest) <= 0 - && interaction.user.id !== interaction.guild.ownerId - ) return await interaction.editReply({ content: `You can't ban ${member.user.tag}` }); - - const banButton1 = new Discord.ButtonBuilder() - .setLabel(`Don't Delete Any`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('0'); - const banButton2 = new Discord.ButtonBuilder() - .setLabel(`Previous Hour`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('1h'); - const banButton3 = new Discord.ButtonBuilder() - .setLabel(`Previous 6 Hours`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('6h'); - const banButton4 = new Discord.ButtonBuilder() - .setLabel(`Previous 12 Hours`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('12h'); - const banButton5 = new Discord.ButtonBuilder() - .setLabel(`Previous 24 Hours`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('24h'); - const banButton6 = new Discord.ButtonBuilder() - .setLabel(`Previous 3 Days`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('3d'); - const banButton7 = new Discord.ButtonBuilder() - .setLabel(`Previous 7 Days`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('7d'); - - const cancelButton = new Discord.ButtonBuilder() - .setLabel(`Cancel`) - .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId('Cancel'); - - const row1 = new Discord.ActionRowBuilder() - .addComponents([ - banButton1, - banButton2, - banButton3, - banButton4, - ]); + try { - const row2 = new Discord.ActionRowBuilder() - .addComponents([ - banButton5, - banButton6, - banButton7, - cancelButton, - ]); + if (member.bannable) { + + if ( + interaction.member.roles.highest.comparePositionTo(member.roles.highest) <= 0 + && interaction.user.id !== interaction.guild.ownerId + ) return await interaction.editReply({ content: `You can't ban ${member.user.tag}` }); + + const banButton1 = new Discord.ButtonBuilder() + .setLabel(`Don't Delete Any`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('0'); + const banButton2 = new Discord.ButtonBuilder() + .setLabel(`Previous Hour`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('1h'); + const banButton3 = new Discord.ButtonBuilder() + .setLabel(`Previous 6 Hours`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('6h'); + const banButton4 = new Discord.ButtonBuilder() + .setLabel(`Previous 12 Hours`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('12h'); + const banButton5 = new Discord.ButtonBuilder() + .setLabel(`Previous 24 Hours`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('24h'); + const banButton6 = new Discord.ButtonBuilder() + .setLabel(`Previous 3 Days`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('3d'); + const banButton7 = new Discord.ButtonBuilder() + .setLabel(`Previous 7 Days`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('7d'); + + const cancelButton = new Discord.ButtonBuilder() + .setLabel(`Cancel`) + .setStyle(Discord.ButtonStyle.Secondary) + .setCustomId('Cancel'); + + const row1 = new Discord.ActionRowBuilder() + .addComponents([ + banButton1, + banButton2, + banButton3, + banButton4, + ]); - const reply = await interaction.editReply({ - content: `Are you sure you want ban ${member} (${member.user.tag}) if yes select one of the Delete Message History buttons (Red ones)`, - components: [ - row1, - row2 - ] - }); + const row2 = new Discord.ActionRowBuilder() + .addComponents([ + banButton5, + banButton6, + banButton7, + cancelButton, + ]); + + const reply = await interaction.editReply({ + content: `Are you sure you want ban ${member} (${member.user.tag}) if yes select one of the Delete Message History buttons (Red ones)`, + components: [ + row1, + row2 + ] + }); - const collector = await reply.createMessageComponentCollector({ time: 60000 }); + const collector = await reply.createMessageComponentCollector({ time: 60000 }); - collector.on('collect', async (int) => { + collector.on('collect', async (int) => { - if (int.customId === 'Cancel') { + if (int.customId === 'Cancel') { - await collector.stop("messageDelete"); - await int.deferUpdate(); - await interaction.deleteReply(); + await collector.stop("messageDelete"); + await int.deferUpdate(); + await interaction.deleteReply(); - } else { + } else { - await collector.stop("banned"); - await int.deferUpdate(); + await collector.stop("banned"); + await int.deferUpdate(); - const duration = ms(int.customId); - await member.ban({ deleteMessageSeconds: duration / 1000, reason: `Banned by ${interaction.user.tag}` }); + const duration = ms(int.customId); + await member.ban({ deleteMessageSeconds: duration / 1000, reason: `Banned by ${interaction.user.tag}` }); - const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); + const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); - let fieldValue = `${member.user.tag} banned by ${interaction.user} \`(${interaction.user.id})\` and all their messages in the last ${ms(duration, { long: true })} were deleted.`; - if (duration === 0) fieldValue = `${member.user.tag} banned by ${interaction.user} \`(${interaction.user.id})\``; + let fieldValue = `${member.user.tag} banned by ${interaction.user} \`(${interaction.user.id})\` and all their messages in the last ${ms(duration, { long: true })} were deleted.`; + if (duration === 0) fieldValue = `${member.user.tag} banned by ${interaction.user} \`(${interaction.user.id})\``; - embed.addFields({ - name: 'Punish Action:', - value: fieldValue - }); + embed.addFields({ + name: 'Punish Action:', + value: fieldValue + }); + + await interaction.message.edit({ embeds: [embed] }).catch(() => null); + + await interaction.editReply({ + content: `${member.user.tag} has been banned successfully.`, + components: [] + }); + + }; + + }); + + collector.on('end', async (collection, reason) => { - await interaction.message.edit({ embeds: [embed] }).catch(() => null); + if (["messageDelete", "banned"].includes(reason)) return; await interaction.editReply({ - content: `${member.user.tag} has been banned successfully.`, - components: [] + components: [ + new Discord.ActionRowBuilder().addComponents([ + banButton1.setDisabled(true), + banButton2.setDisabled(true), + banButton3.setDisabled(true), + banButton4.setDisabled(true) + ]), + new Discord.ActionRowBuilder().addComponents([ + banButton5.setDisabled(true), + banButton6.setDisabled(true), + banButton7.setDisabled(true), + cancelButton.setDisabled(true) + ]), + ] }); - }; + }); + + } else await interaction.editReply({ content: `I can't ban ${member.user.tag}.` }); + + } catch (error) { + await interaction.editReply({ content: `There was an error while banning ${member}, *(${error.message})*` }); + }; + + } else { - }); + const user = await client.users.fetch(id[1]).catch(() => null); - collector.on('end', async (collection, reason) => { + try { - if (["messageDelete", "banned"].includes(reason)) return; + const fetchedBan = await interaction.guild.bans.fetch(user.id).catch(() => null); + if (!fetchedBan) { + + const banButton1 = new Discord.ButtonBuilder() + .setLabel(`Don't Delete Any`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('0'); + const banButton2 = new Discord.ButtonBuilder() + .setLabel(`Previous Hour`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('1h'); + const banButton3 = new Discord.ButtonBuilder() + .setLabel(`Previous 6 Hours`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('6h'); + const banButton4 = new Discord.ButtonBuilder() + .setLabel(`Previous 12 Hours`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('12h'); + const banButton5 = new Discord.ButtonBuilder() + .setLabel(`Previous 24 Hours`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('24h'); + const banButton6 = new Discord.ButtonBuilder() + .setLabel(`Previous 3 Days`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('3d'); + const banButton7 = new Discord.ButtonBuilder() + .setLabel(`Previous 7 Days`) + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId('7d'); + + const cancelButton = new Discord.ButtonBuilder() + .setLabel(`Cancel`) + .setStyle(Discord.ButtonStyle.Secondary) + .setCustomId('Cancel'); + + const row1 = new Discord.ActionRowBuilder() + .addComponents([ + banButton1, + banButton2, + banButton3, + banButton4, + ]); - await interaction.editReply({ + const row2 = new Discord.ActionRowBuilder() + .addComponents([ + banButton5, + banButton6, + banButton7, + cancelButton, + ]); + + const reply = await interaction.editReply({ + content: `Are you sure you want ban ${user} (${user.tag}) if yes select one of the Delete Message History buttons (Red ones)`, components: [ - new Discord.ActionRowBuilder().addComponents([ - banButton1.setDisabled(true), - banButton2.setDisabled(true), - banButton3.setDisabled(true), - banButton4.setDisabled(true) - ]), - new Discord.ActionRowBuilder().addComponents([ - banButton5.setDisabled(true), - banButton6.setDisabled(true), - banButton7.setDisabled(true), - cancelButton.setDisabled(true) - ]), + row1, + row2 ] }); - }); + const collector = await reply.createMessageComponentCollector({ time: 60000 }); - } else await interaction.editReply({ content: `I can't ban ${member.user.tag}.` }); + collector.on('collect', async (int) => { - } catch (error) { - await interaction.editReply({ content: `There was an error while banning ${member}, *(${error.message})*` }); - }; - - } else { - - const user = await client.users.fetch(id[1]).catch(() => null); - - try { - - const fetchedBan = await interaction.guild.bans.fetch(user.id).catch(() => null); - if (!fetchedBan) { - - const banButton1 = new Discord.ButtonBuilder() - .setLabel(`Don't Delete Any`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('0'); - const banButton2 = new Discord.ButtonBuilder() - .setLabel(`Previous Hour`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('1h'); - const banButton3 = new Discord.ButtonBuilder() - .setLabel(`Previous 6 Hours`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('6h'); - const banButton4 = new Discord.ButtonBuilder() - .setLabel(`Previous 12 Hours`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('12h'); - const banButton5 = new Discord.ButtonBuilder() - .setLabel(`Previous 24 Hours`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('24h'); - const banButton6 = new Discord.ButtonBuilder() - .setLabel(`Previous 3 Days`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('3d'); - const banButton7 = new Discord.ButtonBuilder() - .setLabel(`Previous 7 Days`) - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId('7d'); - - const cancelButton = new Discord.ButtonBuilder() - .setLabel(`Cancel`) - .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId('Cancel'); - - const row1 = new Discord.ActionRowBuilder() - .addComponents([ - banButton1, - banButton2, - banButton3, - banButton4, - ]); + if (int.customId === 'Cancel') { - const row2 = new Discord.ActionRowBuilder() - .addComponents([ - banButton5, - banButton6, - banButton7, - cancelButton, - ]); + await collector.stop("messageDelete"); + await int.deferUpdate(); + await interaction.deleteReply(); - const reply = await interaction.editReply({ - content: `Are you sure you want ban ${user} (${user.tag}) if yes select one of the Delete Message History buttons (Red ones)`, - components: [ - row1, - row2 - ] - }); + } else { - const collector = await reply.createMessageComponentCollector({ time: 60000 }); + await collector.stop("banned"); + await int.deferUpdate(); - collector.on('collect', async (int) => { + const duration = ms(int.customId); + await interaction.guild.bans.create(id[1], { deleteMessageSeconds: duration / 1000, reason: `Banned by ${interaction.user.tag}` }); - if (int.customId === 'Cancel') { + const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); - await collector.stop("messageDelete"); - await int.deferUpdate(); - await interaction.deleteReply(); + let fieldValue = `${user ? user.tag : id[1]} banned by ${interaction.user} \`(${interaction.user.id})\` and all their messages in the last ${ms(duration, { long: true })} were deleted.`; + if (duration === 0) fieldValue = `${user ? user.tag : id[1]} banned by ${interaction.user} \`(${interaction.user.id})\``; - } else { + embed.addFields({ + name: 'Punish Action:', + value: fieldValue + }); - await collector.stop("banned"); - await int.deferUpdate(); + await interaction.message.edit({ embeds: [embed] }).catch(() => null); - const duration = ms(int.customId); - await interaction.guild.bans.create(id[1], { deleteMessageSeconds: duration / 1000, reason: `Banned by ${interaction.user.tag}` }); + await interaction.editReply({ + content: `${user ? user.tag : id[1]} has been banned successfully.`, + components: [] + }); - const embed = Discord.EmbedBuilder.from(interaction.message.embeds[0]); + }; - let fieldValue = `${user ? user.tag : id[1]} banned by ${interaction.user} \`(${interaction.user.id})\` and all their messages in the last ${ms(duration, { long: true })} were deleted.`; - if (duration === 0) fieldValue = `${user ? user.tag : id[1]} banned by ${interaction.user} \`(${interaction.user.id})\``; + }); - embed.addFields({ - name: 'Punish Action:', - value: fieldValue - }); + collector.on('end', async (collection, reason) => { - await interaction.message.edit({ embeds: [embed] }).catch(() => null); + if (["messageDelete", "banned"].includes(reason)) return; await interaction.editReply({ - content: `${user ? user.tag : id[1]} has been banned successfully.`, - components: [] + components: [ + new Discord.ActionRowBuilder().addComponents([ + banButton1.setDisabled(true), + banButton2.setDisabled(true), + banButton3.setDisabled(true), + banButton4.setDisabled(true) + ]), + new Discord.ActionRowBuilder().addComponents([ + banButton5.setDisabled(true), + banButton6.setDisabled(true), + banButton7.setDisabled(true), + cancelButton.setDisabled(true) + ]), + ] }); - }; - - }); - - collector.on('end', async (collection, reason) => { - - if (["messageDelete", "banned"].includes(reason)) return; - - await interaction.editReply({ - components: [ - new Discord.ActionRowBuilder().addComponents([ - banButton1.setDisabled(true), - banButton2.setDisabled(true), - banButton3.setDisabled(true), - banButton4.setDisabled(true) - ]), - new Discord.ActionRowBuilder().addComponents([ - banButton5.setDisabled(true), - banButton6.setDisabled(true), - banButton7.setDisabled(true), - cancelButton.setDisabled(true) - ]), - ] }); - }); + } else await interaction.editReply({ content: `${fetchedBan.user.tag} has been already banned.` }); - } else await interaction.editReply({ content: `${fetchedBan.user.tag} has been already banned.` }); + } catch (error) { + await interaction.editReply({ content: `There was an error while banning this user, *(${error.message})*` }); + }; - } catch (error) { - await interaction.editReply({ content: `There was an error while banning this user, *(${error.message})*` }); }; - }; + } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); - } else await interaction.editReply({ content: 'You can\'t use this button. you are not an Admin.' }); + }; }; }; + } catch (error) { + console.error(chalk.bold.redBright(error)); }; }; \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js index 310a2eb..e506df4 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -384,8 +384,8 @@ module.exports = async (client, message) => { console.error(chalk.bold.redBright(error)); - if (error.response) await message.reply({ content: error.response.error.message }); - else if (error.message) await message.reply({ content: error.message }); + if (error.response) await message.reply({ content: error.response.error.message.length > 4000 ? error.response.error.message.substring(0, 3097) + "..." : error.response.error.message }); + else if (error.message) await message.reply({ content: error.message.length > 4000 ? error.message.substring(0, 3097) + "..." : error.message }); });