Discord.js同时运行“ if”语句和“ else语句”

时间:2020-07-04 04:26:52

标签: discord.js

所以我正在编码discord bot,并且我有一条语句应该仅在第二个参数(参数1)为“ version”时发送特定消息。 这是代码:

    case 'help':
                if(args[1] === 'version'){
                    message.channel.send(VERSIONDETAILS)
                }
                else
                message.channel.send('Command list for version ' + VERSION)
                message.channel.send('Prefix: ' + PREFIX)
                message.channel.send(`botdetails: Sends information on the bot \ninvite: Sends a permanent invite link \ninfo: Sends info on Brothaus \nversioninfo: Sends the version number, and latest version details` )
                break;

但是当我运行b!help version命令时,它同时发送VERSIONDETAILS和else语句消息。我该如何解决?

1 个答案:

答案 0 :(得分:2)

它应该看起来像这样,您已经忘记了{}

case 'help':
    if (args[1] === 'version') {
        message.channel.send(VERSIONDETAILS)
    } else {
        message.channel.send('Command list for version ' + VERSION)
        message.channel.send('Prefix: ' + PREFIX)
        message.channel.send(`botdetails: Sends information on the bot \ninvite: Sends a permanent invite link \ninfo: Sends info on Brothaus \nversioninfo: Sends the version number, and latest version details`)
    }
    break;