我正在制作一个 discord bot,其中一个命令是 kick 命令,所以问题是当你输入“=kick info”时,它应该显示一个嵌入,该嵌入将为你提供有关命令的信息,并且它不断给出我的错误
DiscordAPIError: Invalid Form Body user_id: Value "info" is not snowflake.
它曾经工作得很好,但由于某种原因,它开始给我这个错误,不仅是这个命令,还有所有其他命令。
我尝试创建一个单独的命令,如果您输入 =info "command" 将显示嵌入,但没有奏效,如果有解决方法请告诉我。
代码如下:
const Discord = require('discord.js')
module.exports = {
name: 'kick',
description: 'Use this command to kick a member from the server so that they have to recieve an invite to re-join it.',
async execute(client, message, args) {
let PermissionEmbed = new Discord.MessageEmbed()
.setDescription(":no_entry: **You do not have Permission to use this command.**")
.setColor('#FF0000');
let PermissionEmbed2 = new Discord.MessageEmbed()
.setDescription(":no_entry: **I do not have Permission to Kick members.**")
.setColor('#FF0000');
if(!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send(PermissionEmbed);
if(!message.guild.me.hasPermission("KICK_MEMBERS")) return message.channel.send(PermissionEmbed2);
let reason = args.slice(1).join(" ");
const mentionedMember = message.mentions.members.first() || await message.guild.members.fetch(args[0]);
let yes = 'info'
let ErrorEmbed = new Discord.MessageEmbed()
.setDescription(":no_entry: **User could not be kicked, the user's role is higher than mine**")
.setColor('#FF0000');
let ErrorEmbed2 = new Discord.MessageEmbed()
.setDescription(":no_entry: **User could not be kicked, the user's role is higher than Yours**")
.setColor('#FF0000');
let ErrorEmbed3 = new Discord.MessageEmbed()
.setDescription(":no_entry: **You cannot kick me.**")
.setColor('#FF0000');
let ErrorEmbed4 = new Discord.MessageEmbed()
.setDescription(":no_entry: **You cannot kick yourself.**")
.setColor('#FF0000');
const KickedEmbed = new Discord.MessageEmbed()
.setDescription(':white_check_mark: **Successfully Kicked '+mentionedMember.user.tag+'**')
.setColor('2eb82e')
const Embedhelp = new Discord.MessageEmbed()
.setTitle('Kick Command')
.setColor('#6DCE75')
.setDescription('**Description**\nUse this command to kick a member from the server so that they have to recieve an invite to re-join it')
.addFields(
{ name: '**Usage:**', value: '=kick (user) (reason)'},
{ name: '**Example:**', value: '=kick @Michael gtfo'},
{ name: '**Info**', value: 'I cannot kick members that have a higher role than me\nYou cannot kick members that have a higher role than you.\nYou cannot kick me.\nYou cannot kick yourself'}
)
.setFooter(client.user.tag, client.user.displayAvatarURL());
if (!reason) reason = 'No reason given';
if (!args[0]) return message.channel.send(Embedhelp);
if (args[0] === yes.toLowerCase)
if (!mentionedMember) return message.channel.send(Embedhelp);
if (!mentionedMember.kickable) return message.channel.send(ErrorEmbed);
if (mentionedMember.user.id == message.author.id) return message.channel.send(ErrorEmbed4);
if (mentionedMember.user.id == client.user.id) return message.channel.send(ErrorEmbed3);
if (message.member.roles.highest.position <= mentionedMember.roles.highest.position) return message.channel.send(ErrorEmbed2)
const kickEmbed = new Discord.MessageEmbed()
.setTitle('You have been Kicked from '+message.guild.name)
.setDescription('Reason for Kick: '+reason)
.setColor('#6DCE75')
.setTimestamp()
.setFooter(client.user.tag, client.user.displayAvatarURL());
await mentionedMember.send(kickEmbed).catch(err => console.log(err));
await mentionedMember.kick({
days: 7,
reason: reason
}).catch(err => console.log(err)).then(() => message.channel.send(KickedEmbed));
}
}
我尝试在线搜索修复程序,但找不到任何有效的方法。
答案 0 :(得分:0)
如果您的消息内容是 =kick info
,则 args[0]
是字符串 "info"
。当您尝试使用 message.guild.members.fetch(args[0])
获取成员时,它会发送一个请求,其中 user_id
为 "info"
,这不是有效的 snowflake。
一个快速的解决方法是提前检查 args[0]
的值,如果是 "info"
则返回:
module.exports = {
name: 'kick',
description:
'Use this command to kick a member from the server so that they have to recieve an invite to re-join it.',
async execute(client, message, args) {
if (args[0] === 'info')
return message.channel.send('Some info about this command...')
let PermissionEmbed = new Discord.MessageEmbed()
// ...