Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
210
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. const botconfig = require("./botconfig.json");
  4. const fs = require("fs");
  5.  
  6.  
  7. bot.commands = new Discord.Collection()
  8. bot.aliases = new Discord.Collection()
  9.  
  10. fs.readdir("./commands/", (err, files) => {
  11.     if (err) console.log(err);
  12.  
  13.     let jsfile = files.filter(f = f.split(".").pop() === "js")
  14.     if (jsfile.length <= 0)
  15.         console.log("couldn\'t find any commands")
  16.     return;
  17. });
  18.  
  19. jsfile.forEach(f) => {
  20.     let props = require(`./commands/${f}`);
  21.     console.log(`${f} loaded!`);
  22.     bot.commands.set(props.help.name, props);
  23.  
  24.     props.help.aliases.forEach(alias => {
  25.         bot.aliases.set(alias, props.help.name);
  26.     })
  27. }
  28.  
  29. bot.on("ready", async () => {
  30.     console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
  31.     bot.user.setActivity(`with ${bot.guilds.size} servers!`);
  32. })
  33.  
  34. bot.on("message", async message => {
  35.     if (message.channel.type === "dm") return;
  36.     if (message.author.bot) return;
  37.  
  38.     let prefix = botconfig.prefix;
  39.  
  40.     if (!message.content.startsWith(prefix)) return;
  41.     let args = message.content.slice(prefix.length).trim().split(/ +/g);
  42.     let cmd;
  43.     cmd = args.shift().toLowerCase();
  44.     let command;
  45.     let commandfile = bot.commands.get(cmd.slice(prefix.length));
  46.     if (commandfile) commandfile.run(bot, message, args);
  47.  
  48.  
  49.     if (bot.commands.has(cmd)) {
  50.         command = bot.commands.get(cmd);
  51.     } else if (bot.aliases.has(cmd)) {
  52.         command = bot.commands.get(bot.aliases.get(cmd));
  53.     }
  54.     try {
  55.         command.run(bot, message, args);
  56.     } catch (e) {
  57.         return;
  58.     }
  59.  
  60. });
  61.  
  62. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement