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);
}
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