[英]Discord.js v12 Nick command
So basically I have this nick command which changes the specified user nickname but if I will try to run that command on a person that has for example "Staff" Role and also me it'll say that it changed my name but I get an error on console.所以基本上我有这个 nick 命令可以更改指定的用户昵称,但是如果我尝试在一个具有例如“员工”角色的人和我身上运行该命令,它会说它改变了我的名字,但我得到一个错误在控制台上。 now I assume it's happening because the Staff Role is in a higher position from my bot and Idk what is the command or how to fix it.现在我认为它正在发生,因为员工角色在我的机器人和 Idk 的更高 position 和 Idk 什么是命令或如何修复它。
client.on('message', async message => {
if(message.content.toLowerCase().startsWith(prefix + "nick")) {
if(message.content.toLowerCase() == prefix + "nick") return message.channel.send('Pls mention someone and do `.nick @user [your text]`')
const newEmbed = new Discord.MessageEmbed()
.setColor("RANDOM")
if(!message.member.hasPermission("MANAGE_NICKNAMES")) {
return message.channel.send("You do not have permission to do that since you're missing `manage_nicknames` perm")}
if(!message.guild.me.roles.highest.position) return message.channel.send("I can't change that user nickname since my role is lower than his one.")
if(message.author.bot) return;
if(message.guild === null) return
let args = message.content.slice(prefix.length).split(/ +/);
let mentionedUser = message.mentions.members.first() || message.guild.members.cache.get(args[1])
if(mentionedUser.hasPermission("ADMINISTRATOR")) return message.channel.send("I can't change this user nickname since he has `administrator` perm")
let name = args.slice(2).join(" ");
newEmbed.setDescription("**Mention a user to change his nickname.**")
.setTimestamp()
newEmbed.setDescription(`I have successfully changed **${mentionedUser.user.tag}** nickname to **${name}**.`);
mentionedUser.setNickname(name)
message.channel.send(newEmbed);
} else {
if(message.content.toLowerCase() === prefix + "help nick") {
const newEmbed = new Discord.MessageEmbed()
.setColor('#00B2B2')
.setTitle('**Nick Help**')
newEmbed.setDescription('this command is changing peoples names for example `.nick @user 123`.')
.setFooter(`Requested by ${message.author.tag}`, message.author.displayAvatarURL())
.setTimestamp();
message.channel.send(newEmbed)
}
}})
As you well assumed the error is due to the bot having insufficient permissions on those staff members.正如您所假设的那样,错误是由于机器人对这些员工的权限不足。
It would have been useful to have the error in your question, but I guess it's about insufficient permissions.在您的问题中出现错误会很有用,但我想这是因为权限不足。
To resolve this the only way I know is to put the role of your bot higher in the hierarchy than the staff role in the discord guild's roles list.要解决这个问题,我知道的唯一方法是将您的机器人的角色在层次结构中高于 discord 公会角色列表中的员工角色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.