简体   繁体   中英

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:

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.');
            });
        }
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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