简体   繁体   English

Discord.js v12 禁止命令

[英]Discord.js v12 Ban Command

I made a ban command for my discord.js v12 bot.我为我的 discord.js v12 机器人创建了一个禁止命令。 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提前致谢

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 函数。

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

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

This looks like code from my video.这看起来像我视频中的代码。 It is a very simple error I made in the code.这是我在代码中犯的一个非常简单的错误。 The .ban part should actually look like this: .ban 部分实际上应该是这样的:

.ban({ reason: 'your reason here' })

-thesportstacker -thesportsstacker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM