From c25eb03f6b17427e34884700022696b71aaa9f2e Mon Sep 17 00:00:00 2001 From: CodyDimensions <92368816+CodyDimensions@users.noreply.github.com> Date: Thu, 17 Feb 2022 13:16:09 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 1dad5b4bfd197c415e371fe08778a4d02e8589ca Mon Sep 17 00:00:00 2001 From: CodyDimensions <92368816+CodyDimensions@users.noreply.github.com> Date: Thu, 17 Feb 2022 13:16:38 +0800 Subject: [PATCH 2/3] Delete say.js --- say.js | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 say.js 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 - } -} From 0844cdd1ba718d0433266a3d4a020ffe8a423683 Mon Sep 17 00:00:00 2001 From: CodyDimensions <92368816+CodyDimensions@users.noreply.github.com> Date: Wed, 16 Feb 2022 21:16:53 -0800 Subject: [PATCH 3/3] Add files via upload --- purge.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 purge.js 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