Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
190
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.  
  30. bot.on("ready", async () => {
  31.     console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
  32.     bot.user.setActivity(`with ${bot.guilds.size} servers!`);
  33. })
  34.  
  35. bot.on("message", async message => {
  36.     if (message.channel.type === "dm") return;
  37.     if (message.author.bot) return;
  38.  
  39.     let prefix = botconfig.prefix;
  40.  
  41.     if (!message.content.startsWith(prefix)) return;
  42.     let args = message.content.slice(prefix.length).trim().split(/ +/g);
  43.     let cmd;
  44.     cmd = args.shift().toLowerCase();
  45.     let command;
  46.     let commandfile = bot.commands.get(cmd.slice(prefix.length));
  47.     if (commandfile) commandfile.run(bot, message, args);
  48.  
  49.  
  50.     if (bot.commands.has(cmd)) {
  51.         command = bot.commands.get(cmd);
  52.     } else if (bot.aliases.has(cmd)) {
  53.         command = bot.commands.get(bot.aliases.get(cmd));
  54.     }
  55.     try {
  56.         command.run(bot, message, args);
  57.     } catch (e) {
  58.         return;
  59.     }
  60.  
  61. });
  62.  
  63. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement