Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. const botSettings = require("./botsettings.json");
  2. const Discord = require("discord.js");
  3. const fs = require("fs");
  4.  
  5. const prefix = botSettings.prefix;
  6.  
  7. const bot = new Discord.Client({disableEveryone: true});
  8. bot.commands = new Discord.Collection();
  9. bot.aliases = new Discord.Collection();
  10. bot.events = new Discord.Collection();
  11.  
  12. fs.readdir("./commands/", (err,files) => {
  13. if(err) console.log(err);
  14.  
  15.  
  16. let jsfile = files.filter(f => f.split(".").pop() === "js");
  17. if(jsfile.length <= 0) {
  18. console.log("No commands loaded");
  19. return;
  20. }
  21.  
  22. console.log(`Loading ${jsfile.length} commands`);
  23.  
  24. jsfile.forEach((f,i) => {
  25. let props = require(`./commands/${f}`);
  26. console.log(`${i + 1}: ${f} commands loaded`);
  27. bot.commands.set(props.help.name,props);
  28. });
  29. });
  30.  
  31.  
  32. // [START] Ładowanie plików wydarzeń
  33. fs.readdir("./events/", (err,files) => {
  34. if(err) console.log(err);
  35.  
  36.  
  37. let jsfile = files.filter(f => f.split(".").pop() === "js");
  38. if(jsfile.length <= 0) {
  39. console.log("no events command");
  40. return;
  41. }
  42.  
  43. console.log(`Loading ${jsfile.length} commands`);
  44.  
  45. jsfile.forEach((f,i) => {
  46. let eventFunc = require(`./events/${f}`);
  47. console.log(`${i + 1}: ${f} events loaded`);
  48. let eventName = `${f}`;
  49. bot.on(eventName, (...args) => eventFunc.run(client, ...args));
  50. });
  51. });
  52. // [KONIEC] Ładowanie plików wydarzeń
  53.  
  54. bot.on("ready", async() => {
  55. console.log(`Bot is ready ! ${bot.user.username} `);
  56. console.log(bot.commands);
  57. try {
  58. let link = await bot.generateInvite(["ADMINISTRATOR"]);
  59. //console.log(link);
  60. } catch (e) {
  61. console.log(e.stack);
  62. }
  63. });
  64.  
  65. bot.on("message", async message => {
  66. if(message.author.bot) return;
  67. if(message.channel.type === "dm") return;
  68.  
  69.  
  70. let messageArray = message.content.split(" ");
  71. let command = messageArray[0];
  72. let args = messageArray.slice(1);
  73.  
  74. if(!command.startsWith(prefix)) return;
  75.  
  76. let cmd = bot.commands.get(command.slice(prefix.length));
  77. if(cmd) cmd.run(bot, message,args);
  78. });
  79.  
  80. bot.login(botSettings.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement