【发布时间】:2020-04-29 14:55:53
【问题描述】:
我正在尝试让我的第一个不和谐机器人在点击反应后发送消息,
一个表示是的反应,一个表示否的反应
我的代码已经发送了一个带有反应的嵌入
我创建了一个反应收集器,但是 现在唯一的事情是它立即反应(反应没有)两次,甚至在我点击反应之前
非常感谢您的帮助!
到目前为止我的代码:
const {Client, RichEmbed } = require('discord.js');
const client = new Client();
const a =
client.once('ready', () => {
console.log('boogie time!');
});
client.on('message', message => {
if(message.author.bot)
{
if(message.embeds)
{
const embedMsg = message.embeds.find(msg=> msg.title ==='Boogie Time!?');
if(embedMsg)
{
embedMsg.message.react('✅')
.then(reaction => reaction.message.react('❌'))
// This is filter, this specified which reactions it should capture, you can use filter to make sure you're only catching specific reactions by specific user
const filter = (reaction, user) => (reaction.emoji.name === '✅' || reaction.emoji.name === '❌') && user.id === message.author.id;
// Here, we're defining a collector that will be active for 30 seconds and collect reactions that pass the above filter
const collector = embedMsg.message.createReactionCollector(filter, {time: 10000});
// This event is emitted when a reaction passes through the filter
collector.on('collect', r => r.name === '✅' ?
console.log('Reacted Yes') : console.log('Reacted No'));
}
}
return;
}
if(message.content.toLowerCase() === 'boogie')
{
const embed = new RichEmbed();
embed.setTitle("Boogie Time!?")
embed.setColor("GREEN")
embed.setDescription("Are you sure?")
message.channel.send(embed);
};
});
【问题讨论】:
标签: javascript discord discord.js