Bot 如果点击反应的用户具有角色 "ID"
我决定试试这个,但没有成功
if(message.member.roles.cache.has(role.id)) {
console.log(`Yay, the author of the message has the role!`);
} else {
console.log(`Nope, noppers, nadda.`);
}
====这里是主要代码====
sentMessage.react("✅");
message.delete({ timeout: 100 });
const filter = (reaction, user) => {
return !user.bot && ["✅"].includes(reaction.emoji.name);
};
sentMessage
.awaitReactions(filter, {
max: 1,
time: 60000,
})
.then((collected) => {
const reaction = collected.first();
if (reaction.emoji.name === "✅") {
const member = reaction.users.cache.find((user) => !user.bot);
message.author.send(Hello)
答案 0 :(得分:2)
您应该检查做出反应的成员的角色(在 reaction.users.cache
中找到的成员)。 reaction.users.cache
返回一个用户,您需要一个公会成员来获取他们的角色。为此,您可以使用 message.guild.members.fetch()
或 message.guild.member()
。现在您可以检查返回的成员是否具有角色:
sentMessage.awaitReactions(filter, {
max: 1,
time: 60000,
})
.then(async (collected) => {
const reaction = collected.first();
if (reaction.emoji.name === '1️⃣') {
// find the first user who reacted and is not a bot
const userReacted = reaction.users.cache.find((user) => !user.bot);
// get the guild member
const member = await message.guild.member(userReacted);
if (!member.roles.cache.has('ROLE_ID')) return;
message.author.send({
embed: {
color: 3447003,
title: 'Вызов принят',
description: `**Сотрудник:** ${member}`,
timestamp: new Date(),
},
});
}
})