当我尝试使具有正常角色的某人静音时,它给了我您不能使具有相同或更高角色的某人静音?
Posted
技术标签:
【中文标题】当我尝试使具有正常角色的某人静音时,它给了我您不能使具有相同或更高角色的某人静音?【英文标题】:when i try mute someone with the normal role it gives me you cannot mute someone with an equal or higher role? 【发布时间】:2021-09-14 13:14:04 【问题描述】:当我尝试使具有正常角色的人静音时,您不能将具有相同或更高角色的人静音?
我还试图让机器人以“给定用户已静音”作为响应,但是当我将已静音的某人静音时,它只会回复说我已将用户静音。
module.exports =
name: 'mute',
description: "This mutes a member",
execute(message, args)
if (!message.member.hasPermission("MANAGE_ROLES"))
return message.channel.send("Sorry but you do not have permission to mute anyone" );
if (!message.guild.me.hasPermission("MANAGE_ROLES"))
return message.channel.send("I do not have permission to manage roles.");
const user = message.mentions.members.first();
if (!user)
return message.channel.send("Please mention the member to who you want to mute");
if(user.id ===message.author.id)
return message.channel.send("you can not mute yourself");
此代码
// ... Other checks here
// Compared after `user` is defined, and undefined check is done
if (message.member.roles.highest.position)
return message.channel.send('You cannot mute someone with an equal or higher role');
let reason = args.slice(1).join(" ")
if(!reason)
return message.channel.send("Please Give the reason to mute the member")
;
//Mute ROLE
let muterole = message.guild.roles.cache.find(x => x.name === "Muted")
let mainrole = message.guild.roles.cache.find(x => x.name === "Verified")
if(!muterole)
return message.channel.send("This server does not have role with name `Muted`")
user.roles.remove(mainrole)
user.roles.add(muterole)
message.channel.send(`You muted **$message.mentions.users.first().username** Muted by:<@$message.author.id> For \`$reason\``)
user.send(`You are muted in **$message.guild.name**,For \`$reason\``)
const newEmbed = new Discord.MessageEmbed()
.setColor('#1ABC9C')
.setDescription(`$member has now been muted`)
.addField('Moderator', message.member, true)
.addField('Member', member, true)
.addField('Reason', reason)
.setFooter(message.member.displayName, message.author.displayAvatarURL( dynamic: true ))
.setTimestamp()
const channel = message.guild.channels.find(ch => ch.name === 'logs' );channel.sendEmbed(newEmbed)
我也尝试将嵌入发送到特定频道,但由于我无法静音成员,我无法对其进行测试,但如果有任何问题,请更正,谢谢
我收到这个错误
.addField('Member', member, true) ^
ReferenceError:成员未定义
【问题讨论】:
【参考方案1】:您不是在比较作者拥有的最高角色位置与提到的用户拥有的最高角色位置。您只是在检查用户是否具有最高角色位置。
if (message.member.roles.highest.position <= user.roles.highest.position)
return message.channel.send('You cannot mute someone with an equal or higher role');
【讨论】:
你忘了cache
。
抱歉在哪里
const channel = message.guild.channels.find(ch => ch.name === 'logs' );channel.sendEmbed(newEmbed)
还有什么是sendEmbed
发送嵌入我把cache
放在哪里
请自己尝试解决这个问题。我知道 *** 致力于帮助开发人员,但您似乎并不真正知道自己在做什么,我觉得如果您自己查看文档对我们双方都会更好。以上是关于当我尝试使具有正常角色的某人静音时,它给了我您不能使具有相同或更高角色的某人静音?的主要内容,如果未能解决你的问题,请参考以下文章
当我尝试运行我的 webpack-dev-server 时,它给了我以下错误,找不到该模块
如何让普罗米修斯 webflux r2dbc 在春天一起工作?当我尝试从服务运行实际 api 时,它给了我错误