[英]Discord.js message after receiving emoji reaction
It it possible to make a Discord bot send a message once a previous message has received a reaction? 一旦先前的消息收到响应,是否可以使Discord机器人发送消息? I was thinking about something like:
我在想类似的东西:
if(cmd === `${prefix}list`) {
var i = 0;
let embed = new Discord.RichEmbed()
.addField("List", "Content");
let anotherembed = new Discord.RichEmbed()
.addField("Message", "List has been completed!");
return message.channel.send(embed);
do {
message.channel.send(anotherembed + 1);
}
while (i !== 0) && (reaction.emoji.name === "✅");
}
That's not something you should do. 那不是你应该做的。
What you want is message.awaitReactions
. 您想要的是
message.awaitReactions
。
There is a great guide by the DiscordJS team and community that has a great example for awaitReactions
. 有由DiscordJS团队和社区有一个很好的例子一个很大的指导
awaitReactions
。
Here is the link and an example they used: 这是他们使用的链接和示例:
message.react('👍').then(() => message.react('👎'));
const filter = (reaction, user) => {
return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
};
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '👍') {
message.reply('you reacted with a thumbs up.');
}
else {
message.reply('you reacted with a thumbs down.');
}
})
.catch(collected => {
console.log(`After a minute, only ${collected.size} out of 4 reacted.`);
message.reply('you didn\'t react with neither a thumbs up, nor a thumbs down.');
});
You basically need a filter, that only allows for a range of emojis, and a user to "use" them. 基本上,您需要一个过滤器,该过滤器仅允许一定范围的表情符号,并由用户“使用”它们。
And also somewhere on your code you have: 而且在您的代码中的某处您有:
return message.channel.send(embed);
You should remove the return part, or else it will just return and don't do the rest of the code. 您应该删除返回部分,否则它将返回并且不执行其余代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.