【发布时间】:2020-07-23 23:22:09
【问题描述】:
所以我目前正在制作一个不和谐的机器人,所以每当有人输入!true @USER [Location] 时,它都会给@USER 发一条消息,添加一个角色,然后使用以下代码将用户昵称为 [Location]:
const mention = message.mentions.members.first();
msg = message.content.toLowerCase();
if (msg.startsWith(prefix)){
if(message.channel.id === '12345'){
if (msg.startsWith (prefix + "true")){
if(!message.member.hasPermission("MANAGE_NICKNAMES")) return message.reply("You have no permission!");
if (mention == null) { return; }
let args = message.content.split(" ").slice(2);
if ((mention.displayName + " " + args.join(" ")).length > 32) return message.channel.send("The nickname exceeds 32 characters")
if(mention.roles.cache.has('1234567890')){
message.reply("User is already accepted.")
} else {
mention.roles.add('1234567890').then(() => mention.setNickname(mention.displayName+" "+args.join(' ')))
.catch((e) => {
console.log('handle error here: ', e.message)
})
}
}}}
但是,大多数情况下,它会返回 Cannot read property 'first' of null,并且不会更改用户的昵称(仅角色和 DM)。我的代码有什么问题吗?谢谢。
【问题讨论】:
标签: javascript node.js discord discord.js