简体   繁体   English

删除任何消息上的特定反应表情 (Discord.js)

[英]Remove a specific reaction emote on any message (Discord.js)

I want to make a "banned reaction".我想做一个“被禁止的反应”。 I got the following code working, but it only removes reactions for messages the bot sends.我让以下代码正常工作,但它只会删除对机器人发送的消息的反应。

 client.on('messageReactionAdd', async (reaction, user) => { console.log(reaction); if(reaction.emoji.name === 'pinkphallicobject') reaction.remove(); });

How can I get it to remove a specific reaction for all messages from anyone?我怎样才能让它删除对来自任何人的所有消息的特定反应?

For the messageReactionAdd event to fire on old messages you will need to cache the old messages in the server when the ready event is fired you can do it like this:要在旧消息上触发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.');
            });
        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM