Discord bot命令未执行的问题

时间:2020-07-13 19:48:00

标签: javascript discord discord.js

我正在为通过.char执行的discord机器人执行命令,但是,基于.char之后的文本,我需要该机器人以不同的嵌入文本进行响应。例如.char alice->响应1 .char alice 2->响应2。为了实现这一点,我在if语句中添加了响应。像这样:

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

module.exports.run = async (bot, message, args) => {

    console.dir(args);
    if(args === 'alice breaker') { 

            const embed = new Discord.MessageEmbed()
            .setTitle('**Alice Breaker**')
            .setDescription("**Character:** Alice | **Job:** Breaker")
            .setURL('https://sinoalice.game-db.tw/characters/アリス/ブレイカー')
            .setThumbnail('https://i.imgur.com/7a65thH.png')
            .setColor('#E2B007')
            .addFields(
                { name: '**Primary Weapon: **', value: '<:breaker:731691544796594228>', inline:true},
                { name: '**Useable Weapon: **', value: '<:breaker:731691544796594228> <:crusher:731691544985206824> <:gunner:731691544918097930> <:polearm:731691544956108850>', inline:true},
                { name: '**Lv.1**', value: '**Job** Blade 10% UP in areas affiliated with Alice'},
                { name: '**Lv.2**', value: '**Job** Blade 10% UP'},
                { name: '**Lv.3**', value: '**Common** Physical ATK + 50'},
                { name: '**Lv.4**', value: '**Common** Physical DEF + 50'},
                { name: '**Lv.5**', value: '**Job** Blade 10% UP in areas affiliated with Alice'},
                { name: '**Lv.6**', value: '**Common** Physical DEF + 50'},
                { name: '**Lv.7**', value: '**Common** HP + 50'},
                { name: '**Lv.8**', value: '**Common** Physical DEF + 50'},
                { name: '**Lv.9**', value: '**Job** Blade 10% UP in areas affiliated with Alice'},
                { name: '**Lv.10**', value: '**Common** HP + 50'},
                { name: '**Lv.11**', value: '**Job** Blade 20% UP in areas affiliated with Alice'},
                { name: '**Lv.12**', value: '**Common** Physical DEF + 200'},
                { name: '**Lv.13**', value: '**Job** Blade 10% UP in areas affiliated with Alice'},
                { name: '**Lv.14**', value: '**Common** Cost + 2'},
            )

            message.channel.send(embed);

    } else if (args === 'alice paladin') {

        const embed = new Discord.MessageEmbed()
            .setTitle('**Alice Paladin**')
            .setDescription("**Character:** Alice | **Job:** Paladin")
            .setURL('https://sinoalice.game-db.tw/characters/アリス/パラディン')
            .setThumbnail('https://i.imgur.com/LTVLNd2.png')
            .setColor('#E2B007')
            .addFields(
                { name: '**Primary Weapon: **', value: '<:polearm:731691544956108850>', inline:true},
                { name: '**Useable Weapon: **', value: '<:breaker:731691544796594228> <:crusher:731691544985206824> <:gunner:731691544918097930> <:polearm:731691544956108850>', inline:true},
                { name: '**Lv.1**', value: '**Job** Polearm 10% UP in areas affiliated with Alice'},
                { name: '**Lv.2**', value: '**Job** Polearm 10% UP'},
                { name: '**Lv.3**', value: '**Common** Magical ATK + 50'},
                { name: '**Lv.4**', value: '**Common** Magical DEF + 50'},
                { name: '**Lv.5**', value: '**Job** Polearm 10% UP in areas affiliated with Alice'},
                { name: '**Lv.6**', value: 'Common** Magical ATK + 50'},
                { name: '**Lv.7**', value: '**Common** HP + 50'},
                { name: '**Lv.8**', value: 'Common** Magical ATK + 50'},
                { name: '**Lv.9**', value: '**Job** Polearm 10% UP in areas affiliated with Alice'},
                { name: '**Lv.10**', value: '**Common** HP + 50'},
                { name: '**Lv.11**', value: '**Job** Polearm 20% UP in areas affiliated with Alice'},
                { name: '**Lv.12**', value: '**Common** Magical ATK + 200'},
            )

            message.channel.send(embed);
    } else if (args === 'alice mage') {
        const embed = new Discord.MessageEmbed()
            .setTitle('**Alice Mage**')
            .setDescription("**Character:** Alice | **Job:** Mage")
            .setURL('https://sinoalice.game-db.tw/characters/アリス/メイジ')
            .setThumbnail('https://i.imgur.com/e3iNaFU.png')
            .setColor('#E2B007')
            .addFields(
                { name: '**Primary Weapon: **', value: '<:puppeter:731694258314149950>', inline:true},
                { name: '**Useable Weapon: **', value: '<:bard:731694258322538622> <:curser:731694258331058237> <:puppeter:731694258314149950> <:cleric:731694258528190576>', inline:true},
                { name: '**Lv.1**', value: '**Job** Focus 30% UP in areas affiliated with Alice'},
                { name: '**Lv.2**', value: '**Job** Focus 10% UP'},
                { name: '**Lv.3**', value: '**Common** Magical DEF + 100'},
                { name: '**Lv.4**', value: '**Common** Physical DEF + 100'},
                { name: '**Lv.5**', value: '**Job** Focus 10% UP in areas affiliated with Alice'},
                { name: '**Lv.6**', value: 'Common** Magical ATK + 100'},
                { name: '**Lv.7**', value: '**Common** HP + 50'},
                { name: '**Lv.8**', value: 'Common** Physical ATK + 100'},
                { name: '**Lv.9**', value: '**Job** Focus 10% UP in areas affiliated with Alice'},
                { name: '**Lv.10**', value: '**Common** HP + 50'},
                { name: '**Lv.11**', value: '**Common** HP + 200'},
                { name: '**Lv.12**', value: '**Common** HP + 200'},
                { name: '**Lv.13**', value: '**Job** Focus 10% UP in areas affiliated with Alice'},
                { name: '**Lv.14**', value: '**Common** HP + 400'},
                { name: '**Lv.15**', value: '**Common** Magical DEF + 400'},
                { name: '**Lv.16**', value: '**Support** When equipping Mage Jobs, Magical damage 2% UP'},
                
            )
            message.channel.send(embed);
    }  else if (args === 'alice cleric') {
        const embed = new Discord.MessageEmbed()
            .setTitle('**Alice Cleric**')
            .setDescription("**Character:** Alice | **Job:** Cleric")
            .setURL('https://sinoalice.game-db.tw/characters/アリス/クレリック')
            .setThumbnail('https://i.imgur.com/jzuRltm.png')
            .setColor('#E2B007')
            .addFields(
                { name: '**Primary Weapon: **', value: '<:cleric:731694258528190576>', inline:true},
                { name: '**Useable Weapon: **', value: '<:bard:731694258322538622> <:curser:731694258331058237> <:puppeter:731694258314149950> <:cleric:731694258528190576>', inline:true},
                { name: '**Lv.1**', value: '**Job** Staff 30% UP in areas affiliated with Alice'},
                { name: '**Lv.2**', value: '**Job** Staff 10% UP'},
                { name: '**Lv.3**', value: '**Common** Magical DEF + 100'},
                { name: '**Lv.4**', value: '**Common** Physical DEF + 100'},
                { name: '**Lv.5**', value: '**Job** Staff 10% UP in areas affiliated with Alice'},
                { name: '**Lv.6**', value: 'Common** Magical ATK + 100'},
                { name: '**Lv.7**', value: '**Common** HP + 50'},
                { name: '**Lv.8**', value: 'Common** Physical ATK + 100'},
                { name: '**Lv.9**', value: '**Job** Staff 10% UP in areas affiliated with Alice'},
                { name: '**Lv.10**', value: '**Common** HP + 50'},
                { name: '**Lv.11**', value: '**Common** HP + 200'},
                { name: '**Lv.12**', value: '**Common** HP + 200'},
                { name: '**Lv.13**', value: '**Job** Staff 10% UP in areas affiliated with Alice'},
                { name: '**Lv.14**', value: '**Common** HP + 400'},
                
            )
            message.channel.send(embed);
    }

        
} 

module.exports.config = {
    name: "char",
    description: "character description",
    usage: "char",
    accessableby: "Members",
    aliases: []
}

现在,我假设如果我输入.char alice breaker,我会得到args === alice breaker中定义的嵌入文本,依此类推。但是,在不和谐的情况下键入命令将无济于事。如果我看着终端机,这就是我得到的Log 我认为这意味着定义遵循 .char已被识别,但漫游器未发送任何响应。有人有想法吗?

1 个答案:

答案 0 :(得分:1)

像这样检查args是否为“数组”

if (args[0] === 'alice' && args[1] === 'breaker') {
...
}

对于您的secenario来说,最好在不同的行中检查args [0],然后再检查args [1] ...但这是解决此问题的方法,“将数组检查为字符串”。

另外,如您所见

console.dir(args);

线条打印

['alice', 'breaker']

所以您也可以看到args是数组。