![](/img/trans.png)
[英]Discord.js awaitReactions or on messageReactionAdd in private message
[英]DISCORD.JS: Message.awaitReactions not firing
当我运行此代码时,sendReact() 会执行但不会执行任何其他操作——没有错误。 the.catch() function 是唯一在 5 秒后执行的东西。 当我对使用 sendReact() 创建的嵌入做出反应时,没有任何反应。 如果我将代码移到那里,这会发生在我的命令文件和我的 index.js 文件中。 没有任何内容被记录到控制台。
var pick = Math.floor(Math.random() * 3) + 1; // 1-rock 2-paper 3-scissors
let playerPick = 0;
sendReact() // sends the embed message with the reactions
message.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '🌑' || reaction.emoji.name == '📄' || reaction.emoji.name == '✂️'),
{ max: 1, time: 5000 }).then(collected => {
if (collected.first().emoji.name == '🌑') {
console.log('rock');
playerPick = 1;
} else if (collected.first().emoji.name == '📄') {
console.log('paper');
playerPick = 2;
} else if (collected.first().emoji.name == '✂️') {
console.log('scissors');
playerPick = 3;
}
console.log("Player pick: " + playerPick);
console.log("CPU pick: " + pick);
}).catch(() => {
message.reply('No reaction after (how many) seconds, game cancelled.');
});
您正在使用sendReact()
创建嵌入,但随后调用message.awaitReactions(...)
。 那是指哪个消息? 您很可能正在等待对触发此命令的消息的反应,而不是对您使用sendReact()
发送的嵌入消息的反应。 您可以告诉机器人等待对新消息的反应的唯一方法是获取对它的引用,并在该引用上调用awaitReactions()
。
所以,例如:
//in an async function...
let gameMessage = await sendReact();
gameMessage.awaitReactions(...).then(collected => {
//handle reaction
});
这是因为您正在等待对您自己的message
的反应。
您需要让awaitReactions()
收听对您发送的嵌入的反应。
const msg = await sendReact()
msg.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '🌑' || reaction.emoji.name == '📄' || reaction.emoji.name == '✂️'),
{ max: 1, time: 5000 }).then(collected => { })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.