I am trying to make users able to select items from my array and have that gif / image printed within the channel it is sent in. The bot will also check if whatever args the user sent is in the array, if it is the bot will proceed to send the image / gif. If it is not, the bot will sent the incorrect usage embed.
module.exports = {
name: "anime",
description: "Generates random anime gif",
async execute(message, args) {
let animearray = [
"angry",
"anime",
"bite",
"bored",
"bread",
"chocolate",
"cookie",
"cuddle",
"dance",
"drunk",
"happy",
"kill",
"kiss",
"laugh",
"lick",
"lonely",
"pat",
"poke",
"pregnant",
"punch",
"run",
"satouselfies",
"sleep",
"spank",
"steal",
"tickle",
];
// incorrect usage
const inc = new Discord.MessageEmbed()
.setDescription(`The category you selected is currently not avaiable. Please take a look at the current list by using: ${config.PREFIX}list`)
.setColor('#E74C3C')
//selecting a category from array
const announcement = args.slice(1).join(" ")
if(!announcement) return message.reply(inc)
// whatever was selected in const variable would be the data
const outc = new Discord.MessageEmbed()
.setDescription(data)
.setColor('#E74C3C')
await message.channel.send(outc);
},
};
Example
User: <anime angry
Bot: Prints the angry image / gif (since it is in the array)
hope you're having a great day!
this was your code
module.exports = {
name: "anime",
description: "Generates random anime gif",
async execute(message, args) {
let animearray = [
"angry",
"anime",
"bite",
"bored",
"bread",
"chocolate",
"cookie",
"cuddle",
"dance",
"drunk",
"happy",
"kill",
"kiss",
"laugh",
"lick",
"lonely",
"pat",
"poke",
"pregnant",
"punch",
"run",
"satouselfies",
"sleep",
"spank",
"steal",
"tickle",
];
// incorrect usage
const inc = new Discord.MessageEmbed()
.setDescription(`The category you selected is currently not avaiable. Please take a look at the current list by using: ${config.PREFIX}list`)
.setColor('#E74C3C')
//selecting a category from array
const announcement = args.slice(1).join(" ")
if(!announcement) return message.reply(inc)
// whatever was selected in const variable would be the data
const outc = new Discord.MessageEmbed()
.setDescription(data)
.setColor('#E74C3C')
await message.channel.send(outc);
},
};
so all you need is to check if the args.slice(1).join(" ")
exists in the array or no, so just do:
if(!animearray.includes(args.slice(1).join(" ").toLowerCase())) return message.channel.send(inc)
else just check for the args and sent the image/gif depending on it.
example:
if(args.slice(1).join(" ").toLowerCase() == 'dance') return message.channel.send(/* image/gif */)