简体   繁体   English

我想为不和谐做一个随机问题机器人,但我无法弄清楚什么是错的

[英]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.

相关问题 我不知道怎么了 - I can't figure out what's wrong 如何让我的 Discord 机器人(Javascript)回答用户提出的特定问题的随机数? - How can I make my Discord bot (Javascript) answer a random number to a specific question an user asks? 什么是我无法弄清楚的优雅模数? - What's that elegant modulo that I can't figure out? 无法弄清楚RegExp问号是怎么回事 - Can't figure out what's going on with RegExp question mark 我不知道这个正则表达式做错了什么,它应该匹配 id":" 和 " - I can't figure out what i'm doing wrong with this regex, it's suposed to match everything between id":" and " 如何在 Javascript 中为 discord 机器人制作随机发生器? - How can I make a random generator in Javascript for a discord bot? 无法弄清楚这个简单的JS代码出了什么问题 - Can't figure out what's wrong with this simple JS code 无法弄清楚我在这个加密 web 应用程序中做错了什么。 为什么要更改错误的字母? - Can't figure out what I did wrong in this encryption web app. Why it is changing the wrong letters? 我做了一个无限循环,似乎无法弄清楚我做错了什么 - I've made an infinite loop and can't seem to figure out what I did wrong 我不知道我在使用 getDay() 时做错了什么 - I can't figure out what I'm doing wrong with getDay()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM