Advertisement
Guest User

index.js

a guest
Feb 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 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 command 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. const activities_list = [
  54. "Sentinel Scrims",
  55. "Sentinel Elite",
  56. "Sentinel Scrims",
  57. ];
  58.  
  59. bot.on('ready', async () => {
  60. console.log('Im ready, online');
  61. setInterval(() => {
  62. const index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
  63. bot.user.setActivity( activities_list[index] , {type: 'WATCHING'});
  64. }, 4000);
  65.  
  66. });
  67.  
  68. bot.on('message', msg => {
  69. if (msg.channel.type === "dm") return;
  70.  
  71. let msg_array = msg.content.split(" ");
  72. let command = msg_array[0];
  73. let args = msg_array.splice(1);
  74.  
  75. if (!command.startsWith(prefix)) return;
  76.  
  77. if (bot.commands.get(command.slice(prefix.length))){
  78. if (validation (allowedRoles.roles,msg.member.roles.array()) || msg.member.id === owner){
  79. let cmd = bot.commands.get(command.slice(prefix.length));
  80. if (cmd){
  81. cmd.run(bot,msg,args);
  82. }
  83. } else {
  84. msg.channel.send("You don't have access to this bot commands");
  85. }
  86. }
  87.  
  88. });
  89.  
  90.  
  91.  
  92.  
  93.  
  94. // Bot login
  95. bot.login(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement