[英]I wish to make a random question bot for discord, but I can't figure out what's wrong
I wish to make a discord bot that asks better questions than the one we have. 我希望制作一个不和我们提出的问题更好的问题。 The intent is that I can update the questions regularly.
目的是我可以定期更新问题。 I have worked out hosting my bot and have had it join a test server.
我已经设法托管我的机器人并让它加入测试服务器。 But I can't figure out a way to have it call on a random question from a list.
但我无法找到一种方法让它从列表中调用随机问题。 All I can do is make it reply with a set word after inputting ?q.
我所能做的就是在输入后用设定字回复?q。
Also, sorry if this is too much to post, I only just joined StackOverflow. 此外,抱歉,如果发布太多,我只是加入了StackOverflow。
I have tried using a random number generator then having it's result be used to be used as a variable, that variable then being the question. 我尝试过使用随机数生成器,然后将结果用作变量,然后该变量成为问题。 Ie.
IE浏览器。 random number between 1-100, if random number is # then msg.question.
1-100之间的随机数,如果随机数是#则msg.question。 I know at least that I would need to have numbers for each question, so if it were the number 50 that were the result then the question that 50 is associated with will be displayed.
我知道至少我需要为每个问题都有数字,所以如果结果是50,那么将显示50与之相关的问题。
var magic8Ball = {};
magic8Ball.listofquestions = ["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.", "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Very doubtful."];
magic8Ball.getAnswer = function(question) {
var randomNumber = Math.random();
var randomAnswer = Math.floor(randomNumber * this.listofquestions.length);
var answer = this.listofquestions[randomAnswer];
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === '?q') {
// msg.reply('pong');
function() {
magic8Ball.getAnswer(question);
};
}
});
client.login(auth.token);
I wanted it to show random questions but I get this error in my cmd when I deploy the bot 我想让它显示随机问题,但是当我部署机器人时,我的cmd中出现此错误
I have revised and edited your code. 我修改并编辑了你的代码。
listofquestions = ["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.", "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Very doubtful."];
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === '?q') {
msg.reply(listofquestions[Math.floor(Math.random() * listofquestions.length)]);
}
client.login(auth.token);
if you need any other help or clarification on anything feel free to ask and I will edit my answer to your needs. 如果您需要任何其他帮助或澄清任何事情,请随时提出,我将根据您的需求编辑我的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.