所以我对此很陌生。我似乎不知道为什么我的机器人没有检测到玩家是否具有静音角色。
我认为如果我输入“If (Mute)”,它会检测成员是否具有“Muted”角色。它所做的唯一一件事就是说“该成员已被静音”,即使该成员根本没有该角色。我什至切换了它来检查成员是否具有“成员”角色,如果是,则删除该角色并添加静音角色,它确实如此,但是它仍然无法检测该成员是否具有静音角色,只会执行“@member 已被静音!”,而不是“该成员已被静音”
代码:
module.exports = {
name: 'mute',
description: "Mute members",
execute(message, args, Discord, client) {
const Admin = message.member.roles.cache.find(role => role.id === 'AdminIDGoesHere');
const Mod = message.member.roles.cache.find(role => role.id === 'ModIdGoesHere');
if (Admin || Mod) {
const target = message.mentions.users.first();
let memberTarget = message.guild.members.cache.get(target.id);
let Mute = message.guild.roles.cache.find(role => role.id === 'MutedIdGoesHere');
let Member = message.guild.roles.cache.find(role => role.id === 'MemberIdGoesHere');
if (target) {
if (Mute) {
message.reply("That member is muted already!")
} else {
memberTarget.roles.add(Mute);
memberTarget.roles.remove(Member);
message.reply(`<@${memberTarget.user.id}> has been muted!`).then(msg => {
msg.delete({ timeout: 5000 });
})
}
} else {
message.reply("Couldn't find that member!").then(msg => {
msg.delete({ timeout: 5000 });
})
}
} else {
message.reply("You don't have permission to do that!").then(msg => {
msg.delete({ timeout: 5000 })
})
}
}
}
就像我说的,我对这个很陌生,哈哈。我已经查找了几个小时来了解如何做到这一点,我觉得这是一个我无法看到、想到或找到的简单解决方案。任何帮助将不胜感激。谢谢。
答案 0 :(得分:0)
首先,你可以使用
const MutedRole = message.guild.roles.cache.get("ROLE_ID");
const Member = message.member; //No need to add this Variable
然后
message.member.roles.has(MutedRole.id) ? message.member.roles.cache.add(MutedRole) : message.channel.send("This user is already muted")