【发布时间】:2021-10-31 08:18:20
【问题描述】:
我试图让用户能够从我的数组中选择项目,并将该 gif / 图像打印在发送它的通道中。 机器人还将检查用户发送的任何参数是否在数组中,如果是,机器人将继续发送图像/gif。如果不是,机器人将发送不正确的使用嵌入。
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);
},
};
示例
用户:
Bot:打印愤怒的图像/gif(因为它在数组中)
【问题讨论】:
-
您将需要一种将输入映射到表情符号名称的方法。我会使用一个对象,这样您就可以从用户输入中索引,并将表情符号名称作为键/值对的值。然后,您不必循环数组来查找您需要添加的 key=user_summited_value。
标签: javascript arrays discord.js args