Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

javascript - How to get old message reactions

What I'm trying to do is to get username for users who reacts on that message. It's working good but when the bot restarts only new reactions work. how to make it send all users reactions

client.on('ready', () => {
   client.guilds.get('guild_id').channels.get('chnl_id').fetchMessage('msg_id');
});
client.on('messageReactionAdd', (reaction, user) => {
    const { message} = reaction;
    if(message.channel.id == 'chnl_id'){
      if(reaction.emoji.name === "?") {
    message.guild.fetchMember(user.id).then(member => {
      if(user.bot)  return;
    else {
         message.channel.send(reaction.users.map(u => u.username.toString()))
        }
    })
    }}});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have the message, then you can filter the reaction of that message by emojis:

const reaction = await message.reactions.cache.filter(r=> r.emoji.name === '?').first().fetch();

Then you can fetch all reactions with that specific emoji:

await reaction.users.fetch();

Then you can filter from that if you want to (for example your own bot), with:

const filteredReactions = reaction.users.cache.filter(r=> !r.bot);

And don't forget to put these in an async function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...