首页 > 解决方案 > 删除任何消息上的特定反应表情 (Discord.js)

问题描述

我想做一个“被禁止的反应”。我得到了以下代码,但它只删除了对机器人发送的消息的反应。

client.on('messageReactionAdd', async (reaction, user) => {
  console.log(reaction);

  if(reaction.emoji.name === 'pinkphallicobject')
    reaction.remove();
});

我怎样才能让它删除来自任何人的所有消息的特定反应?

标签: javascriptdiscorddiscord.js

解决方案


messageReactionAdd在旧消息上触发事件,您需要在ready触发事件时将旧消息缓存在服务器中,您可以这样做:

client.once('ready', () => {
    var guild = client.guilds.cache.first();// you can find the server you want it to work on in a different way or do this for all servers
    guild.channels.cache.forEach(channel => { 
        if(channel.type == 'text'){//do this for text channels only
                channel.messages.fetch({limit: 100}).then(() => {
                console.log('cached 100 or less messages from the: ' + channel.name + 'text channel.');
            });
        }
    });
}

推荐阅读