diff --git a/README.md b/README.md index cb2bedc..7925e87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Discord.js v13 Say/Echo Slash Command +# Discord.js v13 Purge/Clear Message Slash Command say/echo slash command of discord.js v13 -Youtube tutorial: [Click here to watch video](https://www.youtube.com/watch?v=ceu00tGJ_GY) +Youtube tutorial: [Click here to watch video](https://www.youtube.com/watch?v=5X9xJLwu6cM) ### Subscribe our YouTube Channel [Cody Dimensions Youtube channel](https://www.youtube.com/channel/UChCwEZuaY3fsYRLp5WZ3ZJg) diff --git a/purge.js b/purge.js new file mode 100644 index 0000000..de52090 --- /dev/null +++ b/purge.js @@ -0,0 +1,37 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { MessageEmbed } = require('discord.js'); +const { parse } = require('dotenv'); + +module.exports = { + data: new SlashCommandBuilder() //create a new slash cmd + .setName('purge') // name of ur slash cmd + .setDescription('Purge an amount of message') // description of ur slash cmd + .addIntegerOption((option) => { // add a Integer option which only allow user to type an Integer (number not string or double) + return option + .setName('amount') // name of the option + .setDescription('Amount of message to delete') // description of the slash cmd + .setRequired(true) // required option, must input amount + }), + async execute(client, interaction) { + if(!interaction.member.permissions.has('MANAGE_MESSAGES')) return interaction.reply({ content: "You don't have `MANAGE_MESSAGES` permission to use this command!"}) // return if user don't have manage messages permission + if(!interaction.guild.me.permissions.has('MANAGE_MESSAGES')) return interaction.reply({ content: "I don't have `MANAGE_MESSAGES` permission to execute this command!"}) // return if bot don't have manage messages permission + + let amount = interaction.options.getInteger('amount') // get the integer that user inputted in option + + if(isNaN(amount) || amount < 1) { // if the amount is not valid then return msg + return interaction.reply({ content: '**Please specify a valid amount between 1 - 100!**', ephemeral: true }) + } + + if(parseInt(amount) > 99) { // if the amount is bigger then 99 then return msg + return interaction.reply({ content: '**I can only delete 99 messages once!', ephemeral: true }) + } else { + try{ + let { size } = await interaction.channel.bulkDelete(amount) // get the size of deleted messages from the bulkDelete() + await interaction.reply({ content: `Deleted ${size} messages.`, ephemeral: true }) + } catch(e) { // if there is error (mostly because of messages are older then 14 days) cannot delete and return a msg + console.log(e) + interaction.reply({ content: `I cannot delete messages that is older than 14 days.`, ephemeral: true }) + } + } + } +} \ No newline at end of file diff --git a/say.js b/say.js deleted file mode 100644 index d0e4736..0000000 --- a/say.js +++ /dev/null @@ -1,13 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('say') - .setDescription('Say a message with the bot') - .addStringOption((option) => - option.setName('message').setDescription('The message to say').setRequired(true) - ), - async execute(client, interaction) { - interaction.reply({ content: interaction.options.getString('message'), ephemeral: true }) //get the input text of the options and echo the text - } -}