我刚刚开始使用 javascript 尝试使用 Discord.js 设置一个 Discord 机器人。我想使用这个机器人作为组织袭击的“简单”方式。因此人们只需点击图标即可登录参加突袭。
const Discord = require('discord.js');
const bot = new Discord.Client();
... token 、前缀等
bot.on('message', message => {
if (message.content.startsWith(PREFIX)) {
let args = message.content.substring(PREFIX.length).split(" ");
...一些用于检查命令的内容
message.channel.send('RaidID: ' + RaidID + '\nRaid: GOS \nRaid Leader: <@' + message.author.id + '> \nDate: ' + args[2] + '\nTime: ' + args[3]).then(messageReaction => {
messageReaction.react('✅');
});
到目前为止,代码运行良好。它可以很好地检查日期和时间。现在我想检测某人是否对消息做出了 react ,并通过编辑消息来提及他。我只是不知道如何使用 awaitReactions
。或者如果它甚至可以与 awaitReactions
一起使用。
最佳答案
您可以替换当前的消息功能
message.channel.send('RaidID: ' + RaidID + '\nRaid: GOS \nRaid Leader: <@' + message.author.id + '> \nDate: ' + args[2] + '\nTime: ' + args[3]).then(messageReaction => {
messageReaction.react('✅');
});
使用此功能:
message.channel
.send(
"RaidID: " +
RaidID +
"\nRaid: GOS \nRaid Leader: <@" +
message.author.id +
"> \nDate: " +
args[2] +
"\nTime: " +
args[3]
)
.then((messageReaction) => {
messageReaction.react("✅");
messageReaction.awaitReactions((args, user) => {
return !user.bot && args._emoji.name === "✅";
}, { max: 1 }).then(reaction => {
// SOMEONE REACTED
console.log('REACTION');
});
});
它在 Promise 的 .then
中添加了 .awaitReactions
函数。它检查 react 是否是由用户和表情符号做出的。如果 react 正确,则调用 //SOMEONE REACTED
部分。
关于javascript - Discord.js react 后编辑消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60677089/