Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. // require packages
  2. const Discord = require('discord.js');
  3. const settings = require('./settings.json');
  4. const fs = require('fs');
  5.  
  6. // initialise are bot
  7. const bot = new Discord.Client();
  8. bot.commands = new Discord.Collection();
  9.  
  10. // import bot setting (data)
  11. const prefix = settings.prefix;
  12. const token = settings.token;
  13. const owner = settings.owner;
  14.  
  15. //read commands files
  16. fs.readdir('./cmds', (err,files) => {
  17. if (err) {
  18. console.log(err);
  19. }
  20.  
  21. let cmdFiles = files.filter(f => f.split(".").pop() === "js");
  22.  
  23. if (cmdFiles.length === 0){
  24. console.log("No files found");
  25. return;
  26. }
  27.  
  28. cmdFiles.forEach((f,i) => {
  29. let props = require(`./cmds/${f}`);
  30. console.log(`${i+1}: ${f} loaded`);
  31. bot.commands.set(props.help.name, props);
  32. });
  33. });
  34.  
  35. let raw = fs.readFileSync('./roles.json');
  36. let allowedRoles = JSON.parse(raw);
  37.  
  38. let validation = function(serverRoles, userRoles){
  39. let val = false;
  40. serverRoles.forEach((role) => {
  41. userRoles.forEach((usr) => {
  42. if (role == usr){
  43. val = true;
  44. }
  45. });
  46. });
  47. return val;
  48. }
  49.  
  50.  
  51.  
  52.  
  53. bot.on('ready', async () => {
  54. console.log(`${bot.user.username} is online.`);
  55. bot.user.setActivity(`In A stacked lobby`, {type: "PLAYING"});
  56. });
  57.  
  58.  
  59. bot.on("message" , async msg => {
  60. if (msg.content.startsWith(prefix)){
  61. if (msg.deletable) await msg.delete();
  62. }
  63.  
  64. if (msg.channel.type === "dm") return;
  65.  
  66. let msg_array = msg.content.split(" ");
  67. let command = msg_array[0];
  68. let args = msg_array.slice(1);
  69.  
  70. if (!command.startsWith(prefix)) return;
  71.  
  72. // if (bot.commands.get(command.slice(prefix.length))){
  73. // if (validation(allowedRoles.roles,msg.member.roles.array()) || msg.member.id === owner){
  74. // let cmd = bot.commands.get(command.slice(prefix.length));
  75. // if (cmd){
  76. // cmd.run(bot,msg,args);
  77. // }
  78. // } else {
  79. // msg.channel.send("You dont have access to this bot commands");
  80. // }
  81. }
  82.  
  83. });
  84.  
  85.  
  86. // Bot login
  87. bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement