Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
37 changes: 37 additions & 0 deletions purge.js
Original file line number Diff line number Diff line change
@@ -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 })
}
}
}
}
13 changes: 0 additions & 13 deletions say.js

This file was deleted.