我使用下面的代码。该代码有效,但我希望这样做,因此只要用户对此做出反应,表情符号反应就会在他们对其作出反应时重置,即使这是有道理的。
有人知道这样做的最好方法吗?还是我需要做些其他事情?
if(message.embeds)
{
const embedMsg = message.embeds.find(msg => msg.title === 'Select the games that you play (you can choose multiple)');
if(embedMsg)
{
message.react('746208061550624860')
.then(reaction => reaction.message.react('746203917272219891'))
.then(reaction => reaction.message.react('746207267728392232')
.catch(err => console.error);
}
}
return;
}
if(message.content.toLowerCase() === '?roles')
{
message.delete()
if(message.member.hasPermission('MANAGE_MESSAGES')) {
const embed = new Discord.MessageEmbed();
embed.setTitle('Select the games that you play (you can choose multiple)')
embed.setColor(colors.blue);
embed.setDescription(
"NOTE: When you select any of these you will have access to the community chat of the game\n"+
"<:cod:746208061550624860> - COD\n" +
"<:valoran:746203917272219891> - VALORAN\n" +
"<:warframe:746208599021191190> - WARFRAME\n");
message.channel.send(embed)
} else {
message.reply("You don't have permission to use this command.");
}
}
});
bot.on('messageReactionAdd', (reaction, user) => {
if(user.bot)
return;
var roleName = reaction.emoji.name;
var role = reaction.message.guild.roles.cache.find(role => role.name.toLowerCase() === roleName.toLowerCase());
var member = reaction.message.guild.members.cache.find(member => member.id === user.id);
if(member.roles.cache.has(role.id))
{
member.roles.remove(role.id).then(member => {
console.log("Removed" + member.user.username + "from the" + role.name + "name.");
}).catch(err => console.error);
}
else {
member.roles.add(role.id).then(member => {
console.log('Added' + member.user.username + 'to the' + role.name + ' role.');
}).catch(err => console.error);
}
```
答案 0 :(得分:0)
message.reactions.cache.get('ur_role_id').remove().catch(error => console.error('Failed to remove reactions: ', error));
答案 1 :(得分:0)
您可以使用MessageReaction.remove()
:
reaction.remove(user)
此外,您使这一行过于复杂:
var member = reaction.message.guild.members.cache.find(member => member.id === user.id);
相反,您可以使用Guild.member()
函数:
var member = reaction.message.guild.member(user);
答案 2 :(得分:0)
使用remove()
方法,假设您已将user
定义为做出反应的人
reaction.users.remove(user);