Javascript 收到表情符号反应后的 Discord.js 消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49842712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Discord.js message after receiving emoji reaction
提问by Ned
It it possible to make a Discord bot send a message once a previous message has received a reaction? I was thinking about something like:
一旦先前的消息收到反应,是否可以让 Discord 机器人发送消息?我在想这样的事情:
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 === "?");
}
回答by André
That's not something you should do.
What you want is message.awaitReactions.
There is a great guide by the DiscordJS team and community that has a great example for awaitReactions.
Here is the linkand an example they used:
那不是你应该做的。
你想要的是message.awaitReactions.
DiscordJS 团队和社区有一个很好的指南,其中有一个很好的例子awaitReactions。
这是他们使用的链接和示例:
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.
您应该删除返回部分,否则它只会返回而不执行其余代码。

