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.

Also, sorry if this is too much to post, I only just joined 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. random number between 1-100, if random number is # then 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.

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

0 Answers