Advertisement
Ryyan

Untitled

Aug 31st, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.70 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.  
  15. const ms = require('ms')
  16.  
  17. client.on("ready", () => {
  18.  
  19. // This event will run if the bot starts, and logs in, successfully.
  20. console.log(`logged into ${client.user.tag}!`);
  21. // Example of changing the bot's playing game to something useful. `client.user` is what the
  22. // docs refer to as the "ClientUser".
  23.  
  24. // Set the client user's status
  25. client.user.setStatus('dnd')
  26. client.user.setPresence({
  27. game: {
  28. name: `Discord.js`,
  29. type: "watching",
  30. url: "https://www.twitch.tv/monstercat"
  31. }
  32. });
  33. });
  34.  
  35.  
  36. client.on("message", async message => {
  37.  
  38. //so, here is an anti-link thingy. if a user sends, a discord invite OR a website the bot will delete it return a message, yes there is alot but thats okay, so that your server isn't filled with links or discord invites, and if the user who sent it has permissions it does not delete it.
  39. if (message.content.includes("https://")) {
  40. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  41. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  42. message.delete(1);
  43. message.channel.sendMessage("No links here, " + message.author)
  44. }
  45. if (message.content.includes("http://")) {
  46. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  47. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  48. message.delete(1);
  49. message.channel.sendMessage("No links here, " + message.author)
  50. }
  51. if (message.content.includes("www.")) {
  52. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  53. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  54. message.delete(1);
  55. message.channel.sendMessage("No links here, " + message.author)
  56. }
  57.  
  58.  
  59. if (message.content.includes(".gg/")) {
  60. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  61. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  62. message.delete(1);
  63. message.channel.sendMessage("No links here, " + message.author)
  64. }
  65.  
  66. if (message.content.includes(".gg /")) {
  67. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  68. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  69. message.delete(1);
  70. message.channel.sendMessage("No links here, " + message.author)
  71. }
  72.  
  73. if (message.content.includes(".gg /")) {
  74. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  75. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  76. message.delete(1);
  77. message.channel.sendMessage("No links here, " + message.author)
  78. }
  79.  
  80. if (message.content.includes("discord .gg /")) {
  81. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  82. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  83. message.delete(1);
  84. message.channel.sendMessage("No links here, " + message.author)
  85. }
  86.  
  87. if (message.content.includes("discord .gg")) {
  88. if (message.member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "MANAGE_ROLES", "MANAGE_CHANNELS")) return;
  89. console.log(message.author.tag + ` Posted a link in ${message.guild} ` + ` Their ID: ${message.author.id} `)
  90. message.delete(1);
  91. message.channel.sendMessage("No links here, " + message.author)
  92. }
  93.  
  94. // This event will run on every single message received, from any channel or DM.
  95.  
  96. // It's good practice to ignore other bots. This also makes your bot ignore itself
  97. // and not get into a spam loop (we call that "botception").
  98. if (message.author.bot) return;
  99.  
  100. // Also good practice to ignore any message that does not start with our prefix,
  101. // which is set in the configuration file.
  102. if (message.content.indexOf(config.prefix) !== 0) return;
  103.  
  104. if (message.channel.type === "dm") return; // here, if the a user dm'd the bot the bot will do nothing, this is to prevent your bot from breaking.
  105.  
  106.  
  107. // Here we separate our "command" name, and our "arguments" for the command.
  108. // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
  109. // command = say
  110. // args = ["Is", "this", "the", "real", "life?"]
  111. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  112. const command = args.shift().toLowerCase();
  113.  
  114.  
  115. if (command === "ban") {
  116. //here, we see if the message author has permission to ban members, if not we return a message.
  117. if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("You do not have the following permission:" + `BAN_MEMBERS`)
  118. //here we return a message, if the bot doesn't have permissions in the message guild if not we return a message.
  119. if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send("I don't have permissions to ban members, permission needed: " + `BAN_MEMBERS`)
  120.  
  121. //"message.mentions.members.first()" is a colletion for a mention of a member. so this will be the member who will be banned.
  122. let member = message.mentions.members.first() || message.guild.members.get(args[0]);
  123. //here, if the user didn't mention anyone, or stated their id we return a message.
  124. if (!member) return message.channel.send(`Please either mention a member, or state their id.`)
  125.  
  126. //we need to make sure the bot can ban the member, so if the bot cannot ban the mentioned user we return a message.
  127. if (!member.bannable)
  128. return message.channel.send("I cannot ban that member.")
  129.  
  130.  
  131. // slice(1) removes the first part, which here should be the user mention or ID
  132. // join(' ') takes all the various parts to make it a single string.
  133. let reason = args.slice(1).join(' ');
  134. if (!reason) reason = "No reason provided";
  135.  
  136. // Now, we ban the member.
  137. member.ban(reason + `(Banned by ${message.author.tag})`)
  138. //if there is an error we return a message, which rarely happens.
  139. .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
  140. //here, the bot says the user was successfully banned.
  141. message.channel.send(`${member.user.tag} was Succesfully banned.`)
  142. }
  143.  
  144. if (command === "say") {
  145. // makes the bot say something and delete the message. As an example, it's open to anyone to use.
  146. // To get the "message" itself we join the `args` back into a string with spaces:
  147. const sayMessage = args.join(" ");
  148. // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing.
  149. message.delete().catch(O_o => {});
  150. // And we get the bot to say the thing:
  151. message.channel.send(sayMessage);
  152. }
  153.  
  154. if (command === "purge") {
  155. //here we see if the bot has permissions to delete messages, if not we return a message.
  156. if (!message.guild.me.hasPermission("MANAGE_MESSAGES")) return message.channel.send("I don't have permission to delete messages, permission needed: " + `MANAGE_MESSAGES`)
  157. //here we see if the message author has permissions to delete messages, if not we return a message.
  158. if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("you don't have permission to delete messages, permission needed: " + `MANAGE_MESSAGES`)
  159.  
  160.  
  161. // This command removes all messages from all users in the channel, up to 100.
  162.  
  163. // get the delete count, as an actual number.
  164. const deleteCount = parseInt(args[0], 10);
  165.  
  166. //here, if the amount they specify is under 2 or higher than 100 we return a message.
  167. if (!deleteCount || deleteCount < 2 || deleteCount > 100)
  168. return message.channel.send("Please provide a number between 2 and 100 for the number of messages to delete");
  169.  
  170. // So we get our messages, and delete them. Simple enough, right?
  171. const fetched = await message.channel.fetchMessages({
  172. limit: deleteCount
  173. });
  174. //now here we delete the messages.
  175. message.channel.bulkDelete(fetched)
  176. .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
  177. }
  178.  
  179. if (command === "ping") {
  180. // Calculates ping between sending a message and editing it, giving a nice round-trip latency.
  181. // The second ping is an average latency between the bot and the websocket server (one-way, not round-trip)
  182. //here we send a message.
  183. const m = await message.channel.send("Ping?");
  184.  
  185.  
  186.  
  187. //up top, we sent a message that said: "Ping?" here we edit the message.
  188. m.edit(`:ping_pong: Pong! ` + Math.round(client.ping) + ` ms!`)
  189. }
  190.  
  191. if (message.content.includes("https://")) {
  192. console.log("deleted " + message.content + " from " + message.author)
  193. message.delete(1);
  194. message.channel.sendMessage("No links here, " + message.author)
  195. }
  196. if (message.content.includes("http://")) {
  197. console.log("deleted " + message.content + " from " + message.author)
  198. message.delete(1);
  199. message.channel.sendMessage("No links here, " + message.author)
  200. }
  201. if (message.content.includes("www.")) {
  202. console.log("deleted " + message.content + " from " + message.author)
  203. message.delete(1);
  204. message.channel.sendMessage("No links here, " + message.author)
  205. }
  206.  
  207. if (command === "tempmute") {
  208. //we see if the message author has the "MANAGE_MESSAGES" permission, if they don't we return a message.
  209. if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.reply("You dont have permission to use this command.");
  210.  
  211. if (!message.guild.me.hasPermission("MANAGE_ROLES")) return message.channel.send("I don't have permission to add or remove roles, permission needed: " + `MANAGE_ROLES`)
  212. //we get the person they're trying to mute.
  213. let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  214. //if they didn't specify a member, or don't mention a member we return a message.
  215. if (!tomute) return message.reply("Please specify a member from either their id, or mention them.");
  216. //here we see if the person they're trying to mute has permission the bot will return a message, saying I can't mute them.
  217. if (tomute.hasPermission("MANAGE_MESSAGES")) return message.reply("Can't mute them!");
  218.  
  219. //we make a reason string
  220. let reason = args.slice(2).join(" ");
  221. //if they don't give a reason it will just be no reason given.
  222. if (!reason) reason = "no reason provided"
  223. //this is the mute role it self.
  224. let muterole = message.guild.roles.find(`name`, "Muted");
  225. //start of create role so, if a role named "Muted" isn't in the message guild the bot will create one.
  226. if (!muterole) {
  227. try {
  228. muterole = await message.guild.createRole({
  229. name: "muted",
  230. color: "#000000",
  231. permissions: []
  232. })
  233. message.guild.channels.forEach(async (channel, id) => {
  234. await channel.overwritePermissions(muterole, {
  235. SEND_MESSAGES: false,
  236. ADD_REACTIONS: false
  237. });
  238. });
  239. } catch (e) {
  240. console.log(e.stack);
  241. }
  242. }
  243. //end of create role
  244. let mutetime = args[1];
  245. if (!mutetime) return message.reply("You didn't specify a time!");
  246.  
  247. message.delete().catch(O_o => {});
  248.  
  249. try {} catch (e) {
  250. message.channel.send(`${tomute.user.tag} has been muted for ${mutetime}`)
  251. }
  252. //here we add the role to the specifed member.
  253. await (tomute.addRole(muterole.id));
  254.  
  255.  
  256. message.channel.send(`${tomute.user.tag} has been muted for ${mutetime}.`)
  257.  
  258. setTimeout(function () {
  259. tomute.removeRole(muterole.id);
  260. }, ms(mutetime));
  261. }
  262.  
  263.  
  264.  
  265.  
  266. });
  267. client.login(config.token)
  268. // thank you for reading this, Ryyan#2229 made this.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement