Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Discord = require('discord.js');
- var bot = new Discord.Client();
- var token = "sometoken";
- var randomMessage;
- var randOn = false;
- var responseArray = [ //add more messages here
- "Ayy, lmao!",
- "Say what?",
- "roflmaotntpmp"
- ];
- 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.sendMessage("Already running.");
- }
- else {
- msg.channel.sendMessage("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.sendMessage("Random message disabled.");
- }
- else {
- msg.channel.sendMessage("Not running.");
- }
- }
- });
- bot.login(token);
- function randomIntFromInterval(min, max) {
- return Math.floor(Math.random()*(max-min+1)+min);
- }
- function randMsg(msgChan) {
- console.log("callback");
- var interval = 1000*randomIntFromInterval(timer[0],timer[1]);
- var rand = randomIntFromInterval(0,responseArray.length-1);
- if(responseArray[rand]) {
- msgChan.sendMessage(responseArray[rand]);
- }
- randomMessage = setTimeout(function() {
- randMsg(msgChan);
- }, interval);
- }
Add Comment
Please, Sign In to add comment