【发布时间】:2020-09-01 22:34:44
【问题描述】:
我搜索了有相同错误但没有找到的人。我正在尝试创建一个设置用户昵称的命令,但是在更改昵称时它给了我一个错误(实际上代码可以工作,因为如果我将“提到的成员.setNickname(args)”更改为“提到的成员。 setNickname(message.author.id)" 有效)。
错误:
UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body nick:无法将“['testing']”解释为字符串。
代码:
const Discord = require('discord.js');
const Client = new Discord.Client();
const Command = require('../../Structures/Command');
const { MessageEmbed } = require('discord.js');
const config = require('../../../config.json');
module.exports = class extends Command {
constructor(...args) {
super(...args, {
aliases: ['nickname', 'name'],
description: "changes someone's nickname.",
category: 'mod',
usage: '<@person> <new nickname>',
});
}
async run(message, target) {
let userId = message.content.substring(message.content.indexOf(' ') + 1);
const args = message.content.split(' ').slice(2);
const mentionedMember =
message.mentions.members.first() ||
message.guild.members.cache.get(target) ||
message.guild.members.cache.get(args[0]);
const now = new Date();
if (!mentionedMember) {
try {
if (!message.guild.members.get(args.slice(0, 1).join(' ')))
throw new Error("There isn't someone with this ID!");
user = message.guild.members.get(args.slice(0, 1).join(' '));
user = user.user;
} catch (error) {
return message.channel.send(
`${message.author.username}, this username doesn't exists!`
);
}
}
if (
(mentionedMember.id !== message.guild.owner.id,
mentionedMember.id !== this.client.owners)
) {
if (!message.member.hasPermission('MANAGE_NICKNAMES'))
return message.channel.send("You don't have permissions!");
if (!message.guild.me.hasPermission('MANAGE_NICKNAMES'))
return message.channel.send(
"I don't have permissions to manage nicknames. Give it to me!"
);
if (
mentionedMember.roles.highest.position >=
message.member.roles.highest.position
) {
return message.channel.send("You can't change this user's nickname.");
}
if (!args) {
return message.channel.send('Remember mentioning someone!');
}
const LogChannel = await message.guild.channels.cache.find(
(channel) => channel.id == config.logModeraçãoId
);
var embed = new Discord.MessageEmbed()
.setAuthor(
`${message.author.username} - (${message.author.id})`,
message.author.displayAvatarURL()
)
.setThumbnail(mentionedMember.user.displayAvatarURL())
.setColor('#BA1F1F').setDescription(`
**Member:** ${mentionedMember.user.username} - (${
mentionedMember.user.id
})
**Action:** changing nickname
**Reason:** ${'not specified'}
**Time:** ${now}
`);
LogChannel.send(embed);
message.channel.send('Nickname changed!');
mentionedMember.setNickname(args);
}
}
};
【问题讨论】:
标签: javascript node.js discord discord.js