在某些Discord服务器上,我要添加/删除角色的代码,但是在某些情况下却没有。我检查了一下,它们都具有正确的权限,所以我有些困惑。
每当我运行>addrole
或>removerole
命令时,我总是收到相同的Discord错误消息。它是“:x:找不到静音角色。请确保您没有输入错字(角色也区分大小写!)” 。当用户在键入他们想添加的角色时打错字时,我将其设置为该值。
命令格式如下:
addrole [@User] [角色名称] removerole [@User] [角色名称]
const Discord = require("discord.js");
exports.run = async(bot, message, args) => {
if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send(":x: Insufficient permission.").then(msg => msg.delete(4000));
let rolemember = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if (!rolemember) return message.channel.send(":x: Could not find user.").then(msg => msg.delete(4000));
let role = args.join(" ").slice(22);
if (!role) return mesage.reply(":x: Specify a role.");
let gRole = message.guild.roles.find(`name`, role);
if (!gRole) return message.channel.send(":x: Couldn't find mute role. Make sure you didn't make a typo (roles are case-sensitive too!)");
if (!rolemember.roles.has(gRole.id)) return message.channel.send(`:x: User does not have role "${gRole.name}".`).then(msg => msg.delete(4000));
await (rolemember.removeRole(gRole.id));
try {
rolemember.send(`:white_check_mark: Your role "${gRole.name}" in`, message.guild.name, "has been removed :confused:.");
} catch (e) {
message.channel.send(`:white_check_mark: ${rolemember} Your role "${gRole.name}" has been removed :confused:.`);
}
let removeroleEmbed = new Discord.RichEmbed()
.setDescription("Role Changes")
.setColor("RANDOM")
.addField("Role Removed", gRole)
.addField("Removed From", rolemember)
.addField("Removed By", message.author);
let logChannel = message.guild.channels.find(`name`, "logs-reports");
if (!logChannel) return message.channel.send(":x: Couldn't find logs channel.").then(msg => msg.delete(4000));
logChannel.send(removeroleEmbed);
}
exports.help = {
name: "removerole"
}
我希望应该添加该角色,但是事实并非如此,每次我都会得到相同的错误消息。
答案 0 :(得分:0)
已弃用.find('name', 'name')
。您使用的东西可能不起作用。而是使用let gRole = message.guild.roles.find(r => r.name === role)
。我是这个社区的新手。所以,如果我做错了,请多加注意。
尝试替换let gRole = message.guild.roles.find(“ name”,role);与let gRole = message.guild.roles.find(r => r.name ===角色)这应该起作用,因为它应该是这样,对不起,我不太擅长解释
注意:
Collection.find()
尚未完全弃用,仅格式Collection.find("name", "yourName")
已弃用!