Discord.js 禁止命令中的无效表单正文

Invalid Form Body in Discord.js ban command(Discord.js 禁止命令中的无效表单正文)
本文介绍了Discord.js 禁止命令中的无效表单正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

所以,我一直在尝试发出禁令命令.我基本上在踢命令上使用了相同的系统,但在这里它不起作用,只是给了我一个错误.我很困惑,因为在错误中它没有显示一行代码或其他东西.
我的命令/代码:

So, i have been trying to make a ban command. I basically used the same system on a kick command, but here it didnt work and just gave me an error. I am confused since in the error it doesnt display a line of code or something.
My Command / Code:

module.exports = {
    name: 'ban',
    description: "Ban Command.",
    execute(msg, args){
    const Discord = require('discord.js')
    const Embeds = require('./../embed')
    let perms = msg.member.permissions  
    let has_kick = perms.has("BAN_MEMBERS")
    if (has_kick === true) {
        const toban = msg.mentions.members.first()
        delete args[0]
        var string = args.join(' ')
        Embeds.error(toban, `You have been banned from ${msg.guild.name} by the user ${msg.author} with the reason ${string}`)
        setTimeout(function(){ 
            try {
            toban.ban(`was banned by ${msg.author} for: ${string}`)
            Embeds.kicked(msg.channel, `${toban} has been banned by ${msg.author} from the server with the following reason: ${string}`, `Banned User from the server`)
            } catch {
                Embeds.error(msg.channel, `I dont have permissions to ban ${toban} `, "Error")
            }
         }, 1000); 
    } else {
        const toban = msg.mentions.members.first()
        Embeds.error(msg.channel, `You dont have permissions to Ban ${toban} `, "Error")
    }
}
}

错误:

(node:13896) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
DICT_TYPE_CONVERT: Only dictionaries may be used in a DictType

推荐答案

这很容易解决,你所要做的就是以正确的方式将适量的参数传递给 .ban 功能.

this is pretty easy to solve, all you have to to is pass the right amount of Parameters in the right way to the .ban function.

.ban({ days: 7, reason: 'your reason here' })

https://discord.js.org/#/docs/main/stable/class/GuildMember?scrollTo=ban

这篇关于Discord.js 禁止命令中的无效表单正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Discord.js Arguments With Spaces(Discord.js 带空格的参数)
DiscordJS fetching more then 100 messages(DiscordJS 获取超过 100 条消息)
my discord.js bot doesn#39;t reply to a user message even if there isn#39;t any error(即使没有任何错误,我的 discord.js 机器人也不会回复用户消息)
Make a bot wait for some time before continuing the code(在继续代码之前让机器人等待一段时间)
Set Discord Bot Activity to the number of Online users. Discord.js(将 Discord Bot 活动设置为在线用户数.不和谐.js)
Got quot;Unexpected end of inputquot; in Javascript when making a Discord Bot(得到“输入意外结束;在 Javascript 中制作 Discord Bot)