当用户对消息做出反应时,如何将值存储到变量中?

时间:2021-01-10 16:00:23

标签: discord discord.js

我已经从以下代码中找出了如何让机器人对其消息做出反应:

if(message.content === "!start"){
        message.channel.send(serve).then(message => {
            message.react('764193096060764211');
        })
}

(serve 是一个存储在变量中的嵌入)

我希望用户对它做出反应,而机器人可以利用该信息做一些事情,例如,将值 1 存储到一个名为startingServe 的变量中。如果用户在 5 秒内没有反​​应,我希望机器人发送消息“玩家结束”。我该怎么做呢?期待社区的帮助!如果还有什么需要我回答这个问题,可以问。

1 个答案:

答案 0 :(得分:0)

使用这样的东西:

var startingServe = 0
message.awaitReactions(filter, { max: 1, time: 5000, errors: ['time'] })
    .then(collected => {
        const reaction = collected.first();
        if (reaction.emoji.id == "764193096060764211") {
            startingServe = 1
        } else {
            message.channel.send('Gamer Ended')
        }
    })
    .catch(collected => {
        message.channel.send('Gamer Ended');
    });

this 指南页面上的来源和更多信息。