【问题标题】:Discord.js bot emoji reactions - how to collect first user who reacts instead of message author?Discord.js 机器人表情符号反应 - 如何收集第一个做出反应的用户而不是消息作者?
【发布时间】:2020-08-15 19:01:11
【问题描述】:

所以我正在为我的服务器制作 Discord 机器人,到目前为止它运行良好,除了一个看起来非常小的问题,但尽管阅读了文档,但我找不到解决方案。

基本上我发送带有反应的嵌入,它工作正常,但如果有人在特定时间内没有反应,机器人会创建另一个表情符号反应,这就是问题所在。我希望它收集第一个对新表情符号做出反应的人,而不是消息作者。这是这部分代码:

.catch(collected => {
    message.channel.sendMessage("You run out of time, maybe someone else wants it?");

    const filter = (reaction, user) => {
    return ['????'].includes(reaction.emoji.name) && user.id === message.author.id;
    };

    embedMessage.react('????');

    embedMessage.awaitReactions(filter, {
      max: 1,
      time: 45000,
      errors: ['time']
    }).then(collected => {

    const reaction = collected.first();

    if (reaction.emoji.name === '????'){
      message.channel.sendMessage("Yay.");

    }    
  });    
});

所以我想知道这是否与这部分有关:

return ['????'].includes(reaction.emoji.name) && user.id === message.author.id;

我尝试将 message.author.id 替换为 reaction.users,但它似乎不起作用。

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    这里是基安,

    此代码应该适合您,我已删除对 user.id == message.author.id 的检查。如果它不起作用,请随时发表评论并修复它。

    .catch(collected => {
        message.channel.sendMessage("You run out of time, maybe someone else wants it?");
    
    /*
     * I think that your error his here, you are trying to check if the user's id is the same
     * as the authors id, returning if it isnt, an easy way around this is to simply remove
     * "&& user.id === message.author.id".
     */
    
    const filter = (reaction, user) => ['?'].includes(reaction.emoji.name);
    
    
    // im going to leave everything under here alone
        embedMessage.react('?');
    
        embedMessage.awaitReactions(filter, {
          max: 1,
          time: 45000,
          errors: ['time']
        }).then(collected => {
    
        const reaction = collected.first();
    
        if (reaction.emoji.name === '?'){
          message.channel.sendMessage("Yay.");
    
        }    
      });    
    });
    

    【讨论】:

      猜你喜欢
      • 2021-07-02
      • 2018-04-03
      • 2021-04-04
      • 2018-09-25
      • 2020-07-30
      • 2021-12-17
      • 2021-08-05
      • 2020-08-12
      • 2021-05-08
      相关资源
      最近更新 更多