Javascript discord 8ball命令不选择随机答案集
我正在编写一个discord机器人,我对生成8ball命令感兴趣。我一直在编写它,直到我开始测试它,每当我执行命令“8ball”时,它都会复制文本框中的用户消息。还有,如果没有在文本机器人中添加任何内容,我的机器人会执行“8ball”,有没有办法解决这个问题?这是我的代码:)Javascript discord 8ball命令不选择随机答案集,javascript,discord,discord.js,Javascript,Discord,Discord.js,我正在编写一个discord机器人,我对生成8ball命令感兴趣。我一直在编写它,直到我开始测试它,每当我执行命令“8ball”时,它都会复制文本框中的用户消息。还有,如果没有在文本机器人中添加任何内容,我的机器人会执行“8ball”,有没有办法解决这个问题?这是我的代码:) 您的问题是如何选择项目以及如何发送消息。您更正的代码如下: const answers = [ "It is certain", "It is decidedly so",
您的问题是如何选择项目以及如何发送消息。您更正的代码如下:
const answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes – definitely",
"You may rely on it",
"As I see it",
"yes",
"Most Likely",
"Outlook good",
"Yes",
"Signs point to yes",
];
command(client, "8ball", (message) => {
const question = message.content.replace('_8ball ', '')
const poggers = answers[Math.floor(Math.random() * answers.length)];
message.reply(question + ", " + poggers);
});
什么是行
message.reply(问题,答案*poggers)
应该做什么?message.reply
,就像message.send
,只接受一个参数,即字符串。因此,要么在发送答案之前构建答案,要么直接在message.reply
中使用字符串连接。你可以在上面阅读@SovietSeal“question”指定他们问的问题,“answers*poggers”应该得到答案列表,然后选择一个随机答案粘贴在问题后面
const answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes – definitely",
"You may rely on it",
"As I see it",
"yes",
"Most Likely",
"Outlook good",
"Yes",
"Signs point to yes",
];
command(client, "8ball", (message) => {
const question = message.content.replace('_8ball ', '')
const poggers = answers[Math.floor(Math.random() * answers.length)];
message.reply(question + ", " + poggers);
});