Getting count of a specific reaction on a message

℡╲_俬逩灬. 提交于 2019-12-11 19:06:34

问题


I'm trying to make a bot that will delete messages with a certain amount of thumbsdown reactions. I'm having trouble identifying the count of a specific reaction on a message.

Basically, I've created a command that waits for messages and adds them to my msgarray. After each message, I want to go through the array and delete any messages with the specified amount of reactions.

This is what I have so far:

var msgarray = [];
const msgs = await message.channel.awaitMessages(msg => {
  msgarray.push(msg);
  for (i = 0; i < msgarray.length; i++) {
    // I'm not sure where to go from here, I want to make an if statement that checks
    // for a certain amount of thumbsdown reactions on the message
    if (msgarray[i].reactions) {
      // incomplete
    }
  }
});

This is my first time programming in javascript, so I apologize if this code doesn't make much sense.


回答1:


TextChannel.awaitMessages() resolves with a Collection, so the msg parameter you're using is not a single message, but a Collection of multiple messages.
Also, it would be better to check messages only when they get a reaction, using the messageReactionAdd event, that fires every time someone adds a reaction.
It should look like this:

// this code is executed every time they add a reaction
client.on('messageReactionAdd', (reaction, user) => {
  let limit = 10; // number of thumbsdown reactions you need
  if (reaction.emoji.name == '👎' && reaction.count >= limit) reaction.message.delete();
});


来源:https://stackoverflow.com/questions/53195978/getting-count-of-a-specific-reaction-on-a-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!