【问题标题】:Catch the user that responses to an awaitMessages action捕获响应 awaitMessages 操作的用户
【发布时间】:2020-04-27 05:20:40
【问题描述】:

在我的不和谐机器人中,我有一个打乱单词的命令,第一个在聊天中做出响应的用户会获得奖励。我已经发出了等待消息回复的命令,但是我怎样才能保存回复的人呢?到目前为止,这是我的代码

authorID = msg.author.id;
const filter = response => {
    return response.author.id === authorID;
}

msg.channel.awaitMessages(filter, {
        max: 1,
        time: 5000
    })
    .then(mg2 => {
        if (mg2.first().content === "1") {

            msg.channel.send("you said 1");
        }
    });

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    使用过滤器,您只允许原始 msg 作者输入,您应该这样做,以便它检测 msg.content 是否等于未拼写的单词。你也没有errors: ["time"]

    const filter = m => m.content === unscrabledWord;
    
    msg.channel.awaitMessages(filter, { max: 1, time: 5000, errors: ["time"] })
        .then(collected => {
            const winner = collected.first().author;
            msg.channel.send(`${winner} Won!`)
        })
        .catch(() => msg.channel.send("Nobody guessed it"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 2015-11-07
      • 2020-11-22
      相关资源
      最近更新 更多