Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2.     Modules
  3. ---------------------------------------------------------------------------*/
  4. const Discord = require("discord.js"),
  5.       config = require("./config.json"),
  6.       fs = require("fs");
  7.  
  8.  
  9. /*---------------------------------------------------------------------------
  10.     Command loader
  11. ---------------------------------------------------------------------------*/
  12. let files = fs.readdirSync("./commands/"),
  13.     cmds = new Map();
  14.  
  15. files.forEach(f => {
  16.     let props = require(`./commands/${f}`);
  17.     cmds.set(props.help.name, props);
  18.  
  19.     if(props.help.aliases) {
  20.         props.help.aliases.forEach(a => cmds.set(a, props));
  21.     }
  22. });
  23.  
  24.  
  25. /*---------------------------------------------------------------------------
  26.     Client
  27. ---------------------------------------------------------------------------*/
  28. const bot = new Discord.Client({disableEveryone: true});
  29.  
  30.  
  31. /*---------------------------------------------------------------------------
  32.     Ready event
  33. ---------------------------------------------------------------------------*/
  34. bot.on("ready", () => {
  35.     bot.generateInvite(["ADMINISTRATOR"]).then(console.log);
  36.     console.log(`Ready as ${bot.user.tag}`);
  37. });
  38.  
  39.  
  40. /*---------------------------------------------------------------------------
  41.     Message handler
  42. ---------------------------------------------------------------------------*/
  43. bot.on("message", (message) => {
  44.     if(!message.content.startsWith(config.bot.prefix)) return;
  45.     if(message.author.bot || message.system) return;
  46.     if(message.channel.type.toLowerCase() === "dm") return;
  47.  
  48.     if(!message.guild.me.permissionsIn(message.channel).has(["SEND_MESSAGES", "EMBED_LINKS", "ATTACH_FILES"])) return;
  49.    
  50.  
  51.     /*---------------------------------------------------------------------------
  52.         Command handler
  53.     ---------------------------------------------------------------------------*/
  54.     let split = message.content.split(/ +/g);
  55.     let name = split[0].slice(config.bot.prefix.length).toLowerCase();
  56.     let args = split.slice(1);
  57.  
  58.     let cmd = cmds.get(name);
  59.     if(cmd) cmd.run(bot, message, args);
  60. });
  61.  
  62.  
  63. /*---------------------------------------------------------------------------
  64.     Logging in
  65. ---------------------------------------------------------------------------*/
  66. bot.login(config.bot.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement