Advertisement
Guest User

Index.js

a guest
Nov 19th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. const discord = require("discord.js");
  2. const bot = new discord.Client({
  3. disableEveryone: true
  4. });
  5. const db = require('quick.db')
  6. const fs = require("fs");
  7. const botconfig = require("./botconfig.json");
  8. require("./util/eventHandler")(bot)
  9.  
  10. bot.commands = new discord.Collection();
  11. bot.alias = new discord.Collection();
  12.  
  13. fs.readdir("./commands/", (err, files) => {
  14.  
  15. if (err) console.log(err)
  16. let jsfile = files.filter(f => f.split(".").pop() === 'js')
  17. if (jsfile.length <= 0) {
  18. return console.log("[LOGS] Couldn't find commands!");
  19. }
  20.  
  21. jsfile.forEach((f, i) => {
  22. let pull = require(`./commands/${f}`)
  23. bot.commands.set(pull.config.name, pull);
  24. pull.config.alias.forEach(alias => {
  25. bot.alias.set(alias, pull.config.name)
  26. })
  27. })
  28. })
  29.  
  30. bot.on("message", (message) => {
  31. if (message.channel.type === 'dm') return;
  32. if (message.author.bot) return;
  33. let prefix = botconfig.prefix
  34. let messageArray = message.content.split(" ")
  35. let cmd = messageArray[0]
  36. let args = messageArray.slice(1)
  37.  
  38. if (!message.content.startsWith(prefix)) return;
  39. let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.alias.get(cmd.slice(prefix.length)))
  40. if (commandfile) commandfile.run(bot, message, args)
  41. });
  42.  
  43. bot.on('guildMemberAdd', (member) => {
  44. const usr = member.user
  45. const serv = member.guild
  46. const punishlog = db.fetch(`punishlog_${serv.id}`)
  47. const punishchan = serv.channels.get(punishlog)
  48. const bannedboo = db.fetch(`banned_${usr.id}`)
  49. const reason = db.fetch(`reason_${usr.id}`)
  50. const proof = db.fetch(`proof_${usr.id}`)
  51. if (bannedboo === 'true') {
  52. const guildmode = db.fetch(`guildmode_${serv.id}`)
  53. if (guildmode === 'ban') {
  54. if (punishlog !== 'null') {
  55. const punishchan = serv.channels.get(punishlog)
  56. const punembed = new discord.RichEmbed()
  57. .setTitle(`Global Ban Enforced`)
  58. .setColor(`#ff1919`)
  59. .setThumbnail(usr.displayAvatarURL)
  60. .setDescription(`${usr.tag} (\`${usr.id}\`)`)
  61. .addField(`Action Taken`, `Ban`)
  62. .addField(`Reason`, reason)
  63. .setFooter(`Use .checkban ${usr.id} for more information!`)
  64. punishchan.send(punembed)
  65. }
  66. serv.ban(usr.id, {
  67. reason: reason
  68. })
  69. }
  70. if (guildmode === 'warn') {
  71. if (punishlog !== 'null') {
  72. const punembed1 = new discord.RichEmbed()
  73. .setTitle(`Global Ban Enforced`)
  74. .setColor(`#ffc219`)
  75. .setThumbnail(usr.displayAvatarURL)
  76. .setDescription(`${usr.tag} (\`${usr.id}\`)`)
  77. .addField(`Action Taken`, `Warn`)
  78. .addField(`Reason`, reason)
  79. .setFooter(`Use .checkban ${usr.id} for more information!`)
  80. punishchan.send(punembed1)
  81. }
  82. serv.owner.send(`A globally banned user has joined your server ${serv.name}!\n > **User:** ${usr.tag} (\`${usr.id}\`)\n > **Reason:** ${reason}\n > **Proof:** ${proof}`)
  83. }
  84. }
  85.  
  86. });
  87.  
  88. bot.on("guildCreate", (newGuild) => {
  89. console.log(`Joined server: ${newGuild.name}`)
  90.  
  91. bot.channels.get("645792498995822622").send(`I was added to a guild: \`${newGuild.name}\` with \`${newGuild.members.size}\` members. I am now in ${bot.guilds.size} guilds!`)
  92. });
  93.  
  94. bot.on("guildDelete", (oldGuild) => {
  95. console.log(`Left server: ${oldGuild.name}`)
  96.  
  97. bot.channels.get("645792498995822622").send(`I was removed from a guild: \`${oldGuild.name}\` with \`${newGuild.members.size}\` members. I am now in ${bot.guilds.size} guilds!`)
  98. });
  99.  
  100.  
  101. bot.login(botconfig.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement