Discord.Js Deletemessage() Doesn't Work

Discord.js deleteMessage() doesn't work

You should use <TextChannel>.bulkDelete instead.

Example:

msg.channel.bulkDelete(100).then(() => {
msg.channel.send("Purged 100 messages.").then(m => m.delete(3000));
});

This would delete 2 - 100 messages in a channel for every call to this method so you would not receive 429 (Too many Requests) Error frequently which might result in your token being revoked.

Discord.js delete messages not commands

First check the channel id, then check if the message content is verify else do message.delete() which will delete the message if its not a command. You are doing it in the reverse order, cause you are checking if the message content is verify and then doing message.delete() which deletes the command.

Eg:

if (message.channel.id === '838040640377585664') {
if (message.content === `${prefix}verify`) {
return message.channel.send('verified'); //or do your thing with a return statement
}
message.delete();
}

Basically it will first check if its the channel , and check if the message is !verify if it is, then it will send what ever you do inside the if statement but remember to return(stops further execution of program). If its not the case, then it will delete.
Or you can include them inside an if, else statement.

Eg:

if (message.channel.id === '838040640377585664') {
if (message.content === `${prefix}verify`) {
//do your thing
}
else{
message.delete();
}
}

Delete a Discord message if it doesn't start with "!test"

You can use the startsWith() method to check if the message content starts with the argument provided. You could also just simply delete the message using message.delete():

client.on('message', (message) => {
if (message.channel.id === '823216214737289266') return;

if (!message.content.startsWith('!test')) {
// not sure what J is, so leaving it here
if (J === null) {
setTimeout(() => message.delete(), 1000);
}
}
});

I'm trying to delete messages in discord.js

Since discord.js v12 you need to pass the options such as timeout and reason as an object so your solution is:

messageReaction.delete({ timeout: 5000 });

Delete Messages Discord.js v.13

You can use this code:

message.channel.send(`I deleted ${parts[1]} messages`)
.then(msg => {
setTimeout(() => msg.delete(), 3000)
}).catch((err) => {console.log(err)})


Related Topics



Leave a reply



Submit