最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - messageDeleted event not being triggered - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Mar 23, 2018 at 19:02 André 4,4974 gold badges33 silver badges58 bronze badges asked May 10, 2017 at 23:30 CyberLXCyberLX 2751 gold badge5 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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.

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.

发布评论

评论列表(0)

  1. 暂无评论