Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { prefix, token } = require("./config.json");
  2. const Discord = require("discord.js");
  3. const fs = require("fs");
  4. const bot = new Discord.Client({disableEveryone: true});
  5. bot.commands = new Discord.Collection();
  6.  
  7. fs.readdir("./commands/", (err, files) => {
  8.  
  9.   if(err) console.log(err);
  10.  
  11.   let jsfile = files.filter(f => f.split(".").pop() === "js")
  12.   if(jsfile.length <= 0){
  13.     console.log("Couldn't find commands.");
  14.     return;
  15.   }
  16.  
  17.   jsfile.forEach((f, i) =>{
  18.     let props = require(`./commands/${f}`);
  19.     console.log(`${f} loaded!`);
  20.     bot.commands.set(props.help.name, props);
  21.   });
  22.  
  23. });
  24.  
  25. bot.on("message", async message => {  
  26.   if(message.author.bot) return;
  27.   let messageArray = message.content.split(" ");
  28.   let cmd = messageArray[0];
  29.   let args = messageArray.slice(1);
  30.  
  31.   let commandfile = bot.commands.get(cmd.slice(prefix.length));
  32.   if(commandfile) commandfile.run(bot,message,args);
  33. });
  34.  
  35. bot.on('error', async (err) => {
  36.   console.log(err.stack)
  37. })
  38.  
  39. bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement