Reputation: 25
I'm working on a command for a discord bot that is executed via .char
however, based on the text followed after .char
, I need the bot to respond with different embed texts. e.g. .char alice
-> response 1 .char alice 2
-> response 2. in order to achieve this I have my responses in if statements. like this:
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: []
}
now I assume that if I'd type .char alice breaker
I would get the embed text defined in args === alice breaker
and so forth. however typing the comand on discord does nothing. if I look bag into the terminal this is what I get
I assume that this means that the definition followed after
.char
was recognized, yet no response is sent by the bot. does anyone have an Idea?
Upvotes: 1
Views: 156
Reputation: 5306
Check args as "array" like so,
if (args[0] === 'alice' && args[1] === 'breaker') {
...
}
seems for your secenario, it is better to check args[0] then later args[1] in different lines... But this is solution for this problem, "checking array as string".
Also, as you can see
console.dir(args);
line prints
['alice', 'breaker']
so args are array as you can see too.
Upvotes: 1