我有一个代码,允许用户添加响应以获取角色。但是,如果希望删除反应,我希望我的机器人删除该角色,并且我不知道该怎么做。这是我当前的代码。
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.\n\n**NOTE:**\nCurrently, this command does not support removing your roles. If you want to remove your role, click on the emoji. Then, click on your profile, and click the X next to the role you want to remove. You can always get it back by reacting.`)
message.channel.send(embed).then(sentMessage => {
sentMessage.react("?").then(() => sentMessage.react("⚠️")).then(() => {
const filter = (reaction, user) => {
return true;
}
const collector = sentMessage.createReactionCollector(filter);
collector.on('collect', (reaction, user) => {
if (reaction.emoji.name === '?'){
role = message.guild.roles.cache.find(role => role.name === "ne1 here");
message.member.roles.add(role);
}
else if (reaction.emoji.name === '⚠️'){
role = message.guild.roles.cache.find(role => role.name === "HR notifications");
message.member.roles.add(role);
}
})
})
.catch(() => console.error('One of the emojis failed to react.'));
})
}
});
keepAlive();
client.login(process.env.TOKEN);
如果有人可以告诉我该怎么做,那太好了。