如何在高级命令处理程序(文件)中使用args

时间:2020-06-30 08:26:56

标签: node.js discord discord.js

我最近开始将命令移入文件中,以使它们井井有条。我在使用默认的g!help命令时遇到问题,但是任何带有参数的参数(例如g!help人员)都只会发送与g!help相同的消息。 (index.js中的所有代码都可以)。

代码如下:


module.exports = {
    name: 'help',
    description: "this is help command",
    execute(message, args){
            if (args[1] === 'staff'){
                const embed = new Discord.MessageEmbed()
                .setTitle ("Staff Commands:")
                .addField ("**g!mute <user> <time>**", "Will mute the user for the specified amount of time. **PLEASE REPORT WHY YOU MUTED PERSON IN** #?mute-people")
                .setColor(0xfc8e08)
                message.channel.send(embed);
            }else
            if (args[1] === 'krunker'){
                const embed = new Discord.MessageEmbed()
                .setTitle ("Krunker::")
                .addField ("**g!profile**", "Will give you a link to my Krunker.io profile")
                .addField ("**g!trade**", "Will Display the t&c for trading")
                .addField ("**g!clan**", "will give the link to my Clan [G3O]")
                .addField ("**g!scope**", "will give the scope I made/use")
                .addField ("**g!overlay**", "will give overlay I made/use")
                .addField ("**g!hitmarker**", "will give the hitmarker I made/use")
                .addField ("**g!mod**", "will give the mod I made")
                .addField ("**g!settings**", "will give the settings I use")
                .setColor(0xfce808)
                message.channel.send(embed);
            }else
            if (args[1] === 'socials'){
                const embed = new Discord.MessageEmbed()
                .setTitle ("Socials:")
                .addField ("**g!twitch**", "Will give you a link to my Twitch")
                .addField ("**g!yt**", "Will give the link to my Youtube Channel")
                .addField ("**g!twitter**", "will give the link to my Twitter")
                .addField ("**g!instagram**", "will give the link to my Instagram")
                .addField ("**g!tiktok**", "will give the link to my TikTok")
                .addField ("**g!socials**", "will give the link where you can find all of my socials")
                .setColor(0xfc0808)
                message.channel.send(embed);
            }else{
                const embed = new Discord.MessageEmbed()
                .setTitle ("Commands List:")
                .addField ("**g!help socials**", "Will give you a list of commands for my socials")
                .addField ("**g!help staff**", "Will give a list of commands for STAFF ONLY")
                .addField ("**g!help krunker**", "Will give a list of commands all realted to Krunker")
                .setColor(0x01B8FF)
                message.channel.send(embed)
        
            }
    
    }
   }

1 个答案:

答案 0 :(得分:0)

只是一个小错误,您正在检查args [1]而不是args [0]。