[英]Discord specific roles required for adding a reaction to a message
client.on('messageReactionAdd', async (reaction, user) => {
const role = guild.roles.cache.find((role) => role.name === 'specific role')
if (reaction.emoji.id == '759643335043448834' && reaction.author.roles.has(role.id))
return
else await reaction.message.delete({timeout:2500})
});
so right now this is giving me a error saying guild is not defined.所以现在这给了我一个错误,说公会没有定义。 I want it to remove a specific custom emoji when a user doesn't have a specific role I am kind of confused what to do anyone know the issue?当用户没有特定角色时,我希望它删除特定的自定义表情符号我有点困惑有人知道这个问题该怎么办?
There are two issues.有两个问题。 The first one, obviously, is that guild
is not defined.显然,第一个是guild
没有定义。 Luckily,MessageReaction
has a message
property, which has a guild
property.幸运的是,MessageReaction
有一个message
属性,它有一个guild
属性。
const role = reaction.message.guild.roles.cache.find(
(role) => role.name === 'specific role'
);
First of all, reaction
doesn't have an author
property.首先, reaction
没有author
属性。 Even if it did, it would return a User
object, which you can't access roles from.即使这样做了,它也会返回一个User
对象,您无法从中访问角色。 Read this answer to see the difference.阅读此答案以查看差异。 Instead, you should use the Guild.member()
function.相反,您应该使用Guild.member()
函数。
client.on('messageReactionAdd', async (reaction, user) => {
const guild = reaction.message.guild;
const role = guild.roles.cache.find((role) => role.name === 'specific role');
if (
reaction.emoji.id == '759643335043448834' &&
guild.member(user).roles.has(role.id)
)
return;
reaction.message.delete({ timeout: 2500 });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.