2
votes

I have just started creating a discord bot using discord.js and was trying out the events and came across an issue. The messageDeleted event doesn't trigger when a message gets deleted.

const discord = require('discord.js');
const Client = new discord.Client();
const token = 'bot_token';

Client.on('ready', function(){console.log('Logged on!')});

Client.on('messageDeleted', function(message, channel){
    console.log('Test, a message was deleted.');
});

Client.login(token);

It never prints out 'Test, a message was deleted.' when I delete a message. note I've tried deleting messages already in chat before running the code and deleting messages I created after running the code to see if that was the issue. Still nothing.

2

2 Answers

4
votes

It's because you're putting an event on messageDeleted instead of messageDelete.
Which is a wrong event listener and doesn't catch the correct emitted one.

0
votes

I spent some time researching and testing this MessageDeleted topic. In my configuration, I don't have the "Manage Messages" permission set for Channels. I don't allow anyone to delete messages for anyone else. However, this does not prevent someone from deleting their own message. With "Message Manage" turned off, when a Guild Member deletes their own Message, the "MessageDeleted" never fires. As soon as you grant the "Manage Messages" permission and the member deletes their own message, the MessageDeleted event fires. Anyone with the "Manage Messages" permission will cause the MessageDeleted event to fire.