Advertisement
Ryyan

Untitled

Jun 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. // Include the Discord library
  2. const Discord = require('discord.js');
  3. const bot = new Discord.Client();
  4. const fs = require("fs");
  5. bot.commands = new Discord.Collection();
  6.  
  7.  
  8. fs.readdir("./commands/",(err,files) => {
  9. if(err) console.log(err);
  10.  
  11. let jsfile = files.filter(f=> f.split(".").pop()==="js")
  12. if (jsfile.length <= 0){
  13. console.log("Could not find commands.");
  14. return;
  15. }
  16. jsfile.forEach((f, i)=>{
  17. let props = require(`./commands/${f}`);
  18. console.log(`${f} loaded`);
  19. bot.commands.set(props.help.name, props);
  20. });
  21. })
  22. // When the bot is ready, log on the console all code must go after ready state
  23. bot.on('ready', async () => {
  24. console.log(`${bot.user.username} is online!`);
  25. bot.user.setActivity(":help",{type: "Playing"})
  26. });
  27.  
  28. bot.on('message', async message => {
  29. if (message.author.bot) return;
  30. if (message.channel.type === "dm") return;
  31.  
  32. let prefix = ':';
  33. let messageArray = message.content.split(" ");
  34. let cmd = messageArray[0];
  35. let args = messageArray.slice(1);
  36.  
  37. let commandfile = bot.commands.get(cmd.slice(prefix.length));
  38. if(commandfile) commandfile.run(bot,message,args);
  39.  
  40.  
  41. if(cmd === `${prefix}report`){
  42.  
  43. let rUser = message.guild.member(message.mentions.users.first() ||message.guild.members.get(args[0]));
  44. if (!rUser) return message.channel.send("Couldn't find user.");
  45. let reason = args.join(" ").slice(22);
  46.  
  47. let reportembed = new Discord.RichEmbed()
  48. .setDescription("Reports")
  49. .setColor('#1da598')
  50. .addField("Reported User", `${rUser} with ID: ${rUser.id}`)
  51. .addField("Reported By", `${message.author} with ID: ${message.author.id}`)
  52. .addField("Channel", message.channel)
  53. .addField("Time", message.createdAt)
  54. .addField("Reason", reason);
  55.  
  56. let reportschannel = message.guild.channels.find(`name`, "reports");
  57. if(!reportschannel) return message.channel.send("Couldn't find reports channels.");
  58.  
  59. message.delete().catch(O_o=>{});
  60. reportschannel.send(reportembed);
  61.  
  62. return;
  63. }
  64.  
  65. if(cmd === `${prefix}ban`){
  66. if (!message.guild) return;
  67. let bUser = message.guild.member(message.mentions.users.first() ||message.guild.members.get(args[0]));
  68. if(!bUser) return message.channel.send("Can't find user!");
  69. let bReason = args.join(" ").slice(22);
  70. if(!message.member.hasPermission("MANAGE_MESSAGES"))return message.channel.send("You can't use this command lol")
  71. if(bUser.hasPermission("MANAGE_MEMBERS")) return message.channel.send("That person can't be banned")
  72.  
  73. let banembed = new Discord.RichEmbed()
  74. .setDescription("~Ban~")
  75. .setColor('#1da598')
  76. .addField("Banned user:",`${bUser} with ID ${bUser.id}`)
  77. .addField("Banned by:", `<@${message.author.id}> with id ${message.author.id}`)
  78. .addField("Banned in: ",message.channel)
  79. .addField("Time :",message.createdAt)
  80. .addField("Reason", bReason);
  81.  
  82. let banchannel = message.guild.channels.find(`name`, "incidents");
  83. if(!banchannel) return message.channel.send("Couldn't find incidents channels.");
  84.  
  85. message.delete().catch(O_o=>{});
  86. message.guild.member(bUser).ban(bReason)
  87. banchannel.send(banembed);
  88.  
  89. }
  90.  
  91. if(cmd === `${prefix}kick`){
  92. if (!message.guild) return;
  93. let kUser = message.guild.member(message.mentions.users.first() ||message.guild.members.get(args[0]));
  94. if(!kUser) return message.channel.send("Can't find user!");
  95. let kReason = args.join(" ").slice(22);
  96. if(!message.member.hasPermission("MANAGE_MESSAGES"))return message.channel.send("You can't use this command lol")
  97. if(kUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be kicked")
  98.  
  99. let kickembed = new Discord.RichEmbed()
  100. .setDescription("~Kick~")
  101. .setColor('#1da598')
  102. .addField("Kicked Out:",`${kUser} with ID ${kUser.id}`)
  103. .addField("Kicked by:", `<@${message.author.id}> with id ${message.author.id}`)
  104. .addField("Kicked in: ",message.channel)
  105. .addField("Time :",message.createdAt)
  106. .addField("Reason", kReason);
  107.  
  108. let kickchannel = message.guild.channels.find(`name`, "incidents");
  109. if(!kickchannel) return message.channel.send("Couldn't find incidents channels.");
  110.  
  111. message.delete().catch(O_o=>{});
  112. message.guild.member(kUser).kick(kReason)
  113. kickchannel.send(kickembed);
  114.  
  115. }
  116.  
  117.  
  118. });
  119. //A message listener the start of the message to start with &&play in server
  120.  
  121. bot.login('');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement