Advertisement
Ryyan

Untitled

Aug 5th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. // Load up the discord.js library
  2. const Discord = require("discord.js");
  3.  
  4. // This is your client. Some people call it `bot`, some people call it `self`,
  5. // some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
  6. // this is what we're refering to. Your client.
  7. const client = new Discord.Client();
  8.  
  9. // Here we load the config.json file that contains our token and our prefix values.
  10. const config = require("./config.json");
  11. // config.token contains the bot's token
  12. // config.prefix contains the message prefix.
  13.  
  14. const prefix = "."
  15.  
  16. client.on("ready", () => {
  17. // This event will run if the bot starts, and logs in, successfully.
  18.  
  19. console.log(`logged in as ${client.user.tag}`);
  20. // Example of changing the bot's playing game to something useful. `client.user` is what the
  21. // docs refer to as the "ClientUser".
  22. client.user.setPresence({
  23. game: {
  24. name: `helping over ${client.guilds.size} servers!`,
  25. type: "streaming",
  26. url: "https://www.twitch.tv/monstercat"
  27. }
  28. });
  29.  
  30. const delay = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
  31.  
  32. client.on("message", async message => {
  33.  
  34.  
  35.  
  36. // This event will run on every single message received, from any channel or DM.
  37. // It's good practice to ignore other bots. This also makes your bot ignore itself
  38. // and not get into a spam loop (we call that "botception").
  39. if (message.author.bot) return;
  40.  
  41.  
  42. // Also good practice to ignore any message that does not start with our prefix,
  43. // which is set in the configuration file.
  44. if (message.content.indexOf(config.prefix) !== 0) return;
  45.  
  46. // Here we separate our "command" name, and our "arguments" for the command.
  47. // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
  48. // command = say
  49. // args = ["Is", "this", "the", "real", "life?"]
  50. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  51. const command = args.shift().toLowerCase();
  52.  
  53. // Let's go with a few common example commands! Feel free to delete or change those.
  54. if (command === "ban") {
  55.  
  56. if(!message.guild.me.hasPermission("BAN_MEMBERS")) return message.react('❌'), message.channel.send('I don\'t have permissions to ban members. please contact a server admin')
  57.  
  58.  
  59. if (!message.member.hasPermission("BAN_MEMBERS")) return message.react('❌'), message.channel.send('Sorry, but you don\'t have permission to ban members.')
  60.  
  61.  
  62.  
  63. let member = message.mentions.members.first()
  64. if (!member) return message.react('❌'), message.channel.send('Hey! you didn\'t mention a user.')
  65.  
  66.  
  67. if (!member.bannable)
  68. return message.react('❌'), message.channel.send('Sorry, but i cannot ban that user.')
  69.  
  70. let reason = args.slice(1).join(' ');
  71. if (!reason) reason = "no reason provided."
  72.  
  73.  
  74. member.send(`Hey, mate you\'ve been banned in ${message.guild.name} by ${message.author.tag} because: "${reason}" 🇫`);
  75. await delay(100); // 100 msec = 0.1 seconds
  76. member.ban(reason)
  77. message.channel.send(`${member} was successfully banned by ${message.author.tag} for: "${reason}", can we get a f in the chat?`)
  78. message.react('🇫'), message.react('✅')
  79.  
  80. }
  81.  
  82. if (command === "kick") {
  83.  
  84. if(!message.guild.me.hasPermission("KICK_MEMBERS")) return message.react('❌'), message.channel.send('I don\'t have permissions to kick members. please contact a server admin')
  85.  
  86. if (!message.member.hasPermission("KICK_MEMBERS")) return message.react('❌'), message.channel.send('Sorry, but you don\'t have permission to kick members.')
  87.  
  88.  
  89. let member = message.mentions.members.first()
  90. if (!member) return message.react('❌'), message.channel.send('please provide a user to kick.')
  91.  
  92. if (!member.kickable)
  93. return message.react('❌'), message.channel.send('I cannot ban that user. they could be a admin, be higher than me, etc.')
  94.  
  95. let reason = args.slice(1).join(' ');
  96. if (!reason) reason = "no reason provided."
  97.  
  98.  
  99.  
  100. member.send(`Hey, mate you\'ve been kicked in ${message.guild.name} by ${message.author.tag} because: "${reason}" 🇫`);
  101. await delay(500); // 100 msec = 0.1 seconds
  102. member.kick(reason)
  103. message.channel.send(`${member} was successfully kicked by ${message.author.tag} for: "${reason}", can we get a f in the chat?`)
  104. message.react('🇫'), message.react('✅')
  105.  
  106. }
  107.  
  108.  
  109. });
  110. });
  111. client.login(config.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement