我正在研究一个功能反应角色机器人。我正在尝试找出如何添加一个过滤器,该过滤器将忽略我已分配的其他表情符号。除了我或其他人尝试使用我分配的表情符号之外的表情符号与该僵尸程序反应之外,该僵尸程序工作正常。
client.on('message', message => {
if(message.author.bot || message.embeds)
embedMsg = message.embeds.find(msg => msg.title === 'Server Roles') ? message : undefined
if(embedMsg)
{
embedMsg.react('755602275963109536')
.then
(reaction => reaction.message.react('755604749814071366'))
.then(reaction => reaction.message.react('755605241067601960'))
.then(reaction => reaction.message.react('755604978571280466'))
.then(reaction => reaction.message.react('755604795292909589'))
.then(reaction => reaction.message.react('755605048666620075'))
.then(reaction => reaction.message.react('755604953229164594'))
.then(reaction => reaction.message.react('755604994656436346'))
.then(reaction => reaction.message.react('755605995195072603'))
.then(reaction => reaction.message.react('755605032124022814'))
.then(reaction => reaction.message.delete(20000))
.then(msg => console.log("Deleted message"))
.catch(() => console.error('One of the emojis failed to react.'));
return;
}
client.on('messageReactionAdd', (reaction, user) => {
if (user.bot) return;
var roleName = reaction.emoji.name;
console.log(roleName);
var role = reaction.message.guild.roles.find(
role => role.name.toLowerCase() === roleName.toLowerCase()
);
var member = reaction.message.guild.members.find(
(member) => member.id === user.id
);
//remove role
if (member.roles.has(role.id)) {
member
.removeRole(role.id)
.then((member) => {
console.log(
'Removed' + member.user.username + ' from the ' + role.name + ' role.'
);
})
.catch((err) => console.error);
//add role
} else {
member
.addRole(role.id)
.then((member) => {
console.log(
'Added ' + member.user.username + ' to the ' + role.name + ' role.'
);
})
.catch((err) => console.error);
}
});
答案 0 :(得分:0)
您可以制作一个接受的表情符号ID数组,并针对给定的反应测试每个ID。
return visit if visit else "None."