Discord bot not saying random message

I’ve scripted a discord bot to tell random messages at the chat by the moment I type !on in the channel.
But it doesnt, I’m not sure what code is wrong.

Here are some of the code I suspect they cause this issue.

var randomMessage;

var randOn = false;

var responseArray = [
var prefix = "!";

var timer = [5,10]; //set min and max in seconds for random messages

 

bot.on("ready", () => {

    console.log("Bot online and ready on " + bot.guilds.size + " server(s).");

});

 

bot.on('message', (msg) => {

  if (msg.content.startsWith(prefix + "on")) {

        if (randOn) {

            msg.channel.send("Already running.");

        }

        else {

            msg.channel.send("Random message started.")

        randomMessage = setTimeout(function() {

                randMsg(msg.channel);

            }, 1000*timer[0]);

        }

  }

  else if (msg.content.startsWith(prefix + "off")) {

        if (randOn) {

            clearTimeout(randomMessage);

            msg.channel.send("Random message disabled.");

        }

        else {

            msg.channel.send("Not running.");

        }

  }

});
function randomIntFromInterval(min, max) {

  return Math.floor(Math.random()*(max-min+1)+min);

}

 

function randMsg(msgChannel) {

    console.log("callback");

    var interval = 1000*randomIntFromInterval(timer[0],timer[1]);

  var rand = randomIntFromInterval(0,responseArray.length-1);

  if(responseArray[rand]) {

    msgChannel.sendMessage(responseArray[rand]);

  }

    randomMessage = setTimeout(function() {

        randMsg(msgChannel);

    }, interval);

}

You can’t just give us snippets of code. You have to show us more than taht. Like the first snippet is missing the end bracket.

var responseArray = [ //add more messages here

  "BROOM!! BROOM!!",

  "San pedro vendió la vaca Josefina, ¿me ayudas a recuperarla? :toncc:",

  "¿Donde está Rodolfo el arbol?",

  "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",

  "AaAaaaAaaAaAaaAaAAAaaAAaaaAAAaaAAaaAAAaAaa",

  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",

  "SULLIVAN, SUELTA A LA NIÑA! :realgun:",

  "Papá trajo galletas, ¿quién quiere?",

  "Failure is an option here. -Elon Musk",

  "Qué hermosas son las playas de bolivia!",

  "El vato que prefiere inyecciones en vez de pastillas me asusta.",

  "EAT YOUR CEREAL! :rawr:",

  "Pescado de Pollo.",

  "I'am the medic. :drzoka:",

  "Los gusanos fritos son pura proteina. :pogtasty:",

  "Mi creador me trata mal, me pega por las noches. :sadmo:",

  "ARARARRAR! ARARRRRRARAR!! ARARRARARRAR!!!",

  "No mastiques el agua.",

  "Les voy a contar un secreto...",

  "pls meme",

  "@Bob Ross te ves muy bien hoy.",

  "He escuchado.. Anime?...",

  "Tengo hambre...",

  "Nadie te ama, ni el oso amoroso. :kekw:",

  "THIS IS MADNESS!",

  "BRuUHUHuHuHuHuhH",

  "No olviden darle de comer al perrocoptero.",

  "Dato Curioso: El sudor de los hipopótamos es rojo, y no es sangre lo que sudan.",

  "Dato Curioso: Los delfines duermen con la mitad de su cerebro.",

  "Pablo, give me a taco.",

  "MMMMMMMMmmmmmmmmmmmm patas",

  "JAja thats true :yesser:",

  "Hoy JP desayunará a tus muertos."

];

Those are just the stupid random messages I added lmao

1 Like

Ya know that happened here.

yo, don’t read those if you don’t wanna get some brain disease. Just help me with this coding dude.

1 Like

ok thanks for the tip! I’ll debug your code from what I can see.

1 Like

k thanks. Im just too new in this :I

3 Likes