2024-05-11 21:57:50 +00:00
const { SlashCommandBuilder , PermissionsBitField } = require ( 'discord.js' ) ;
2024-05-11 06:55:44 +00:00
const informationStatus = "[INFO]: " ;
const warningStatus = "[WARNING]: " ;
const errorStatus = "[ERROR]: " ;
2024-05-11 21:57:50 +00:00
const wait = require ( 'node:timers/promises' ) . setTimeout ;
2024-05-11 06:55:44 +00:00
module . exports = {
data : new SlashCommandBuilder ( )
. setName ( 'clear' )
. setDescription ( 'Clears a certain amount of text!' )
. addNumberOption ( option =>
option . setName ( 'amount' )
. setDescription ( 'Set the amount to clear!' )
. setRequired ( true ) ) ,
async execute ( interaction ) {
const amount = interaction . options . getNumber ( 'amount' ) ;
2024-05-11 21:57:50 +00:00
if ( amount <= 0 ) return interaction . reply ( { content : "<:xmark:1238963594758979736> This is not a valid number!" , ephemeral : true } ) ;
if ( ! interaction . member . permissions . has ( PermissionsBitField . Flags . ManageMessages ) ) return interaction . reply ( { content : "<:xmark:1238963594758979736> You dont have permission to use this command" , ephemeral : true } ) ;
2024-05-11 06:55:44 +00:00
try {
await interaction . channel . bulkDelete ( amount ) ;
2024-05-11 21:57:50 +00:00
await interaction . reply ( { content : ` <:checkmark:1238964552482422844> Deleted ${ amount } of messages! ` , ephemeral : false } ) ;
console . log ( informationStatus + ` Cleared ${ amount } amount of text in # ${ interaction . channel . name } with id of ${ interaction . channel . id } ` ) ;
await wait ( 6_000 ) ;
await interaction . deleteReply ( ) ;
2024-05-11 06:55:44 +00:00
} catch ( error ) {
2024-05-11 21:57:50 +00:00
await interaction . reply ( { content : "Sorry! Could not execute the clear command. Something went wrong" , ephemeral : true } ) ;
2024-05-11 06:55:44 +00:00
console . log ( errorStatus + "Something went wrong while trying to clear messages! Debug information is below." ) ;
console . error ( error ) ;
}
}
}