Advertisement
Guest User

Index.js

a guest
Nov 19th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const discord = require('discord.js');
  2. const bot = new discord.Client({disableEveryone: true})
  3.  
  4. bot.commands = {};
  5. bot.alias = {};
  6.  
  7. bot.on('ready', () => {
  8.     console.log(`Logged in as ${bot.user.username}`)
  9. });
  10.  
  11. bot.on('error', (err => {
  12.     console.log(err)
  13. }));
  14.  
  15. fs.readdir("./commands/", (err, files) => {
  16.  
  17.     if (err) console.log(err)
  18.     let jsfile = files.filter(f => f.split(".").pop() === 'js')
  19.     if (jsfile.length <= 0) {
  20.       return console.log(chalk.red("[LOGS] Couldn't find commands!"));
  21.     }
  22.  
  23.     jsfile.forEach((f, i) => {
  24.       let pull = require(`./commands/${f}`)
  25.       bot.commands.set(pull.config.name, pull);
  26.       pull.config.alias.forEach(alias => {
  27.         bot.alias.set(alias, pull.config.name)
  28.       })
  29.     })
  30.   })
  31.  
  32. bot.on("message", (message) => {
  33.     if (message.channel.type === 'dm') return;
  34.     if (message.author.bot) return;
  35.     let prefix = botconfig.prefix
  36.     let messageArray = message.content.split(" ")
  37.     let cmd = messageArray[0]
  38.     let args = messageArray.slice(1)
  39.  
  40.     if (!message.content.startsWith(prefix)) return;
  41.     let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.alias.get(cmd.slice(prefix.length)))
  42.     if (commandfile) commandfile.run(bot, message, args)
  43.   });
  44.  
  45. bot.login('NjQ2NTQ1Mjc0MTY0MjE1ODI5.XdS2Zw._rgqVKUwTOPTGfr8Nid0LYEjfDs');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement