Discord.js v12禁止命令 [英] Discord.js v12 Ban Command

查看:52
本文介绍了Discord.js v12禁止命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为discord.js v12机器人设置了禁止命令.但是,每当我运行命令时,都会出现错误.这是我的代码:

I made a ban command for my discord.js v12 bot. However whenever I run the command I get an error. Here is my code:

const Discord = require('discord.js');

module.exports = {
    name: "ban",
    description: "Kicks a member from the server",

    async run (client, message, args) {

        if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send('You can\'t use that!')
        if(!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send('I don\'t have the right permissions.')

        const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]);

        if(!args[0]) return message.channel.send('Please specify a user');

        if(!member) return message.channel.send('Can\'t seem to find this user. Sorry \'bout that :/');
        if(!member.bannable) return message.channel.send('This user can\'t be banned. It is either because they are a mod/admin, or their highest role is higher than mine');

        if(member.id === message.author.id) return message.channel.send('Bruh, you can\'t ban yourself!');

        let reason = args.slice(1).join(" ");

        if(!reason) reason = 'Unspecified';

        member.ban(`${reason}`).catch(err => { 
          message.channel.send('Something went wrong')
            console.log(err)
        })

        const banembed = new Discord.MessageEmbed()
        .setTitle('Member Banned')
        .setThumbnail(member.user.displayAvatarURL())
        .addField('User Banned', member)
        .addField('Kicked by', message.author)
        .addField('Reason', reason)
        .setFooter('Time kicked', client.user.displayAvatarURL())
        .setTimestamp()

        message.channel.send(banembed);


    }
}

这是我每次运行命令时遇到的错误

This is the error I get whenever I run the command

 DiscordAPIError: Invalid Form Body
    DICT_TYPE_CONVERT: Only dictionaries may be used in a DictType
        at RequestHandler.execute (/home/runner/SweatyBeautifulHelpfulWorker/node_modules/discord.js/src/rest/RequestHandler.js:170:25)
        at processTicksAndRejections (internal/process/task_queues.js:97:5) {
      method: 'put',
      path: '/guilds/751424392420130907/bans/155149108183695360',
      code: 50035,
      httpStatus: 400
    }

我不明白如何纠正代码中的问题.我对编码有点陌生.你能帮帮我吗!预先感谢

I could'nt understand how to correct the problem in the code. I'm a bit new to coding. Can you please help me out!. Thanks in advance

推荐答案

这很容易解决,您所要做的就是以正确的方式将正确数量的Parameters传递给.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 v12禁止命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆