Advertisement
Guest User

Index.js

a guest
Jul 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const botconfig = require("./botconfig.json");
  2. const Discord = require("discord.js");
  3. const bot = new Discord.Client({disableEveryone: true});
  4. const fs = require("fs");
  5. bot.commands = new Discord.Collection();
  6. bot.aliases = new Discord.Collection();
  7.  
  8. bot.on('ready', function() {
  9.     console.log(`${bot.user.username} is online and running in ${bot.guilds.size} servers!`);
  10.     console.log(`${bot.user.username}'s prefix is ${botconfig.prefix}`);
  11.    setInterval(async () => {
  12.        
  13.  const statuslist = [
  14.    "Jac.",
  15.    "/help"    
  16.  ];
  17.  const random = Math.floor(Math.random() * statuslist.length);
  18.  try {
  19.    await bot.user.setPresence({
  20.      game: {
  21.        name: `${statuslist[random]}`,
  22.        type: "LISTENING",
  23.       url: 'https://www.twitch.tv/DiveristyRises'
  24.       },
  25.       status: "online"
  26.     });
  27.   } catch (error) {
  28.     console.error(error);
  29.   }
  30. }, 9000);
  31. });
  32.  // Command handler
  33.  fs.readdir("./commands/", (err, files) => {
  34.  
  35.   if(err) console.log(err)
  36.   let jsfile = files.filter(f => f.split(".").pop() === "js")
  37.   if(jsfile.length <= 0) {
  38.       return console.log("Couldn't find commands!")
  39.   }
  40.  
  41.   jsfile.forEach((f, i) => {
  42.       let pull = require(`./commands/${f}`);
  43.      
  44.       bot.commands.set(pull.config.name, pull);
  45.       pull.config.aliases.forEach(alias => {
  46.           bot.aliases.set(alias, pull.config.name)
  47.       })
  48.   })
  49. });
  50.  
  51.  
  52. // Message Event
  53. bot.on("message", async message => {
  54.   if(message.author.bot || message.channel.type === "dm") return;
  55. if(message.content === "gn") return message.channel.send("goodnight");
  56.  
  57.   let prefix = botconfig.prefix;
  58.   let messageArray = message.content.split(" ")
  59.   let cmd = messageArray[0].toLowerCase();
  60.   let args = messageArray.slice(1);
  61.  
  62.  
  63.   if(!message.content.startsWith(prefix)) return;
  64.   console.log(`${message.author.username}#${message.author.discriminator} used ${cmd} in ${message.guild.name} Channel: ${message.channel.name}`)
  65.   let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix.length)))
  66.   if(commandfile) commandfile.run(bot,message,args)
  67. });
  68.  
  69.  
  70. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement