Discord JS - 如果对消息做出反应的用户具有特定角色,我想添加一个角色
Discord JS - If the user reacting to message has a specific role I want to add a role
我正在尝试创建一个更复杂的反应角色函数。
基本上我想实现的是,如果一个用户有两个角色,它应该可以访问一些频道。
因此,我尝试执行此操作的方法是在单击授予成员第二个角色的反应时检查用户是否具有其中一个角色。如果用户有其他角色,他应该获得解锁这些频道的第三个角色。
但是,我一直无法弄清楚如何查看对消息做出反应的人的角色。
client.on('messageReactionAdd', async (reaction, user) => {
const message = await reaction.message.fetch(true);
const channelAccess = '918617193988649002';
const foodSweden = message.guild.roles.cache.find(role => role.name === '');
const foodCategoryReaction = '';
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id === channelAccess) {
if (reaction.emoji.name === foodCategoryReaction && message.member.roles.has('')) {
await reaction.message.guild.members.cache.get(user.id).roles.add(foodSweden);
} else {
return;
}
}
});
这是代码。我不确定 message.member.roles.has('')
应该如何编码。
我已经尝试 reaction.message.member.roles.has('')
、reaction.member.roles.has('')
、user.roles.has('')
并为用户移出了成员。
I'm uncertain how message.member.roles.has('') should be coded. I've tried reaction.message.member.roles.has(''), reaction.member.roles.has(''), user.roles.has('') and shifted out member for user.
其中 None 是现有方法。 member.roles
没有 .has()
方法。而用户代表公会外的一般discord用户;用户没有角色,只有公会成员有角色。 discord.js 中任何管理器的 .has()
方法通常也使用 ID(这是它们在底层 Collection
缓存中映射到的内容),而不是名称或其他属性。见 docs.
检查做出反应的成员是否具有特定角色的方法如下:
const hasRole = reaction.message.member.roles.cache.some(role => role.name == "");
公会成员的角色缓存几乎总是up-to-date,所以你真的不需要做任何获取。您可以在这里依赖角色缓存。
我正在尝试创建一个更复杂的反应角色函数。
基本上我想实现的是,如果一个用户有两个角色,它应该可以访问一些频道。 因此,我尝试执行此操作的方法是在单击授予成员第二个角色的反应时检查用户是否具有其中一个角色。如果用户有其他角色,他应该获得解锁这些频道的第三个角色。
但是,我一直无法弄清楚如何查看对消息做出反应的人的角色。
client.on('messageReactionAdd', async (reaction, user) => {
const message = await reaction.message.fetch(true);
const channelAccess = '918617193988649002';
const foodSweden = message.guild.roles.cache.find(role => role.name === '');
const foodCategoryReaction = '';
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id === channelAccess) {
if (reaction.emoji.name === foodCategoryReaction && message.member.roles.has('')) {
await reaction.message.guild.members.cache.get(user.id).roles.add(foodSweden);
} else {
return;
}
}
});
这是代码。我不确定 message.member.roles.has('')
应该如何编码。
我已经尝试 reaction.message.member.roles.has('')
、reaction.member.roles.has('')
、user.roles.has('')
并为用户移出了成员。
其中I'm uncertain how message.member.roles.has('') should be coded. I've tried reaction.message.member.roles.has(''), reaction.member.roles.has(''), user.roles.has('') and shifted out member for user.
None 是现有方法。 member.roles
没有 .has()
方法。而用户代表公会外的一般discord用户;用户没有角色,只有公会成员有角色。 discord.js 中任何管理器的 .has()
方法通常也使用 ID(这是它们在底层 Collection
缓存中映射到的内容),而不是名称或其他属性。见 docs.
检查做出反应的成员是否具有特定角色的方法如下:
const hasRole = reaction.message.member.roles.cache.some(role => role.name == "");
公会成员的角色缓存几乎总是up-to-date,所以你真的不需要做任何获取。您可以在这里依赖角色缓存。