如何计算反应Discord JS

时间:2020-09-11 15:29:35

标签: javascript node.js discord discord.js

我在discord.js中发出了一个轮询命令,但是我不确定如何获得对特定表情符号做出反应的人数。这是我的代码:

if (!args[1]) return message.channel.send('You need to ask a question.');
let pollq = args.join(' ');
let whoask = msg.author.username;

const poll = new D.MessageEmbed()
 .setTitle('New Poll')
 .setAuthor(
  'Cleansound',
  'https://yt3.ggpht.com/a/AATXAJxJ8Qab93CDlxO7tOg06Jifb1Z1-14j1Xj2nt3dNg=s100-c-k-c0xffffffff-no-rj-mo'
 )
 .setDescription(`${whoask} Baru Saja Membuat Pollin question baru`)
 .setDescription(`${pollq}`)
 .addField(` ? `, 'Untuk Setuju')
 .addField(` ? `, 'Untuk Tidak Setuju')
 .setTimestamp()
 .setFooter(
  'Cleansound Host',
  'https://yt3.ggpht.com/a/AATXAJxJ8Qab93CDlxO7tOg06Jifb1Z1-14j1Xj2nt3dNg=s100-c-k-c0xffffffff-no-rj-mo'
 );
await poll.react('?');
await poll.react('?');
msg.channel.send(poll);

1 个答案:

答案 0 :(得分:4)

您可以使用Message.reactions.cache,它将返回该消息上每个MessageReaction的集合。从那里,您可以使用Collection#get()获取您喜欢的反应,并使用MessageReaction#count查看有多少人对此反应。

poll.reactions.cache.get('?').count;