Discord.js Bot命令,从随机的预制列表中说出一个句子 [英] Discord.js Bot Command that says a sentence from a random list of premade ones

查看:54
本文介绍了Discord.js Bot命令,从随机的预制列表中说出一个句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,基本上,我正在尝试为我的机器人发出某个命令,然后我将看看你们中是否有人可以帮助编写一些东西.我想创建一个命令,用户在其中键入命令,然后机器人会从预先编写的句子列表中随机选择.我正在尝试创建一个事实命令,当您这样做时,事实会以随机事实做出响应.

So basically, I'm trying to make a certain command for my bot, and I was going to see if any of you could help write something up. I want to make a command where a user types the command and then the bot will randomly choose from a list of prewritten sentences. I'm trying to make a fact command where when you do !fact it responds with a random fact.

注意:这将用于我的命令处理程序.

Note: This would be for my command handler.

谢谢大家的帮助!

推荐答案

var facts = ["Your facts", "...", "..."];
var fact = Math.floor(Math.random() * facts.length);
message.channel.send(facts[fact]);

这是一个命令,将按照您在问题中的描述进行操作!

Here's a command that will do this as you described it in your question!

最诚挚的问候,Monkeyyy11

Best regards, Monkeyyy11

这篇关于Discord.js Bot命令,从随机的预制列表中说出一个句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆