Discord.js 解决命令处理程序问题的 Ban 命令

Discord.js Breaking down Ban Command for Command Handler issues

我有一个相当大的 index.js 所以我一直忙于将它剥离到单独的命令文件中,我已经成功地将我的所有代码导出到单独的命令中,除了禁止。到目前为止,禁令代码按预期工作,但如果输入 18 位用户 ID,并且他们已经离开服务器,它应该检查并将其记录在 .json 文件中,但目前它没有超过 if (isNaN(args[1])) 它不会接受任何东西,数字和/或字母都会导致 "You need to enter a vlaid @Member or UserID #" 这非常令人沮丧,因为我花了几个小时才在我的 index.js

中工作

 run: async (bot, message, args) => {

        if (!message.member.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("You do not have permission to perform this command!")

        const user1 = message.mentions.users.first();
        var member = message.mentions.members.first()


        if (member) {

            const member = message.mentions.members.first()

            let reason = args.slice(2).join(' '); // arguments should already be defined
            var user = message.mentions.users.first();

            member.ban({ reason: `${args.slice(2).join(' ')}` }).then(() => {
                let uEmbed = new RichEmbed()
                    .setTitle('**' + `Sucessfully Banned ${user1.tag}!` + '**')
                    .setThumbnail('https://i.gyazo.com/8988806671312f358509cf0fd69341006.jpg')
                    .setImage('https://media3.giphy.com/media/H99r2HtnYs492/giphy.gif?cid=ecf05e47db8ad81dd0dbb6b132bb551add0955f9b92ba021&rid=giphy.gif')
                    .setColor(0x320b52)
                    .setTimestamp()
                    .setFooter('Requested by ' + message.author.tag, 'https://i.gyazo.com/8988806671312f358509cf0fd69341006.jpg')
                message.channel.send(uEmbed);

            }).catch(err => {
                message.channel.send('I was unable to kick the member');
                console.log(err);
            });
        } else {
            let user = message.mentions.users.first(),
                userID = user ? user.id : args[1]

            if (isNaN(args[1])) return message.channel.send("You need to enter a vlaid @Member or UserID #");

            if (args[1].length <= 17 || args[1].length >= 19) return message.channel.send("UserID # must be 18 Digits");

            if (userID) {
                let bannedIDs = require('./bannedIDs.json').ids || []

                if (!bannedIDs.includes(userID)) bannedIDs.push(userID)

                fs.writeFileSync('./bannedIDs.json', JSON.stringify({ ids: bannedIDs }))
                let reason = args.slice(2).join(' '); 
                let uEmbed = new RichEmbed()
                    .setTitle('**' + `UserID #${args[1]}\n Will be Banned on Return!` + '**')
                    .setThumbnail('https://i.gyazo.com/8988806671312f358509cf0fd69341006.jpg')
                    .setImage('https://i.imgur.com/6Sh8csf.gif')
                    .setColor(0x320b52)
                    .setTimestamp()
                    .setFooter('Requested by ' + message.author.tag, 'https://i.gyazo.com/8988806671312f358509cf0fd69341006.jpg')
                    message.channel.send(uEmbed);

            } else {
                message.channel.send('Error')
            }
        }
    }

}






首先,if (args[1].length <= 17 || args[1].length >= 19可以减少到if(args[1].length !== 18),我看到你的另一个post,它表明你通过了这个错误,这是正确的吗?