【发布时间】:2020-11-21 11:18:20
【问题描述】:
现在,我正在尝试制作一个反应角色机器人,但我不断收到错误消息。这是我的代码。
const Discord = require('discord.js');
const keepAlive = require('./server');
const client = new Discord.Client();
client.on('message', message => {
if (message.author !== null && message.author.bot) return;
if (message.toString().toLowerCase().includes('start reaction roles')) {
message.delete()
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('React to get notified')
.setDescription(`Hello! Please react to this message to get a role. Here are the roles that you can get by reacting:\n> ???? | React with this emoji to get <@&727665971443269635> notifications.\n> ⚠️ | React with this emoji to get <@&727633811709362187>.\nYou can chose one of the emojis, or both of them.`)
message.channel.send(embed).then(sentMessage => {
sentMessage.react("????")
.then(() => sentMessage.react("⚠️"))
.catch(() => console.error('One of the emojis failed to react.'));
})
const collector = sentMessage.createReactionCollector();
collector.on('collect', (reaction, user) => {
if (reaction.emoji.name === '????'){
role = message.guild.roles.find(role => role.name === "ne1 here");
message.member.addRole(role);
}
else if (reaction.emoji.name === '⚠️'){
role = message.guild.roles.find(role => role.name === "HR notifications");
message.member.addRole(role);
}
})
}
});
keepAlive();
client.login(process.env.TOKEN);
上面写着const collector = sentMessage.createReactionCollector(); 的部分不起作用。如果有人可以帮我解决这个问题,那就太好了。
【问题讨论】:
标签: bots discord.js