Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 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 = {
  11. "token" : "[Add your bot token here",
  12. "prefix" : "~",
  13. "mode" : "FULL",
  14. "authorID" : "270404393411674115" //Original Author's discord ID
  15. };
  16.  
  17. let logChannel = "";
  18. let suggestChannel = "";
  19.  
  20. const menus = {}
  21. menus.helpMain = `I see you need some help! What can I help you with?
  22. :one: General Commands.
  23. :two: Moderation
  24. :three: Administration/Maintenance
  25. :four: Games
  26. :five: About DungeonMeister
  27.  
  28. To navigate, react with any number listed below.
  29. This menu will self-destruct after 30 seconds of inactivity :bomb:`;
  30.  
  31. menus.helpGeneral = `\`~help\` - Displays this interactive help menu.
  32. \`~ping\` - Pong! returns the ping times of the bot.
  33. \`~suggest [suggestion]\` - Send a feature suggestion to the developer, it will be voted on to be implemented.
  34. React with :one: to go back`;
  35.  
  36. menus.helpMods = `Click :one: to go back`;
  37.  
  38. menus.helpAdmin = `\`~set [variable] [value]\` - Sets a value within the bot, such as the "playing" status.
  39. React with :one: to go back`;
  40.  
  41. menus.helpGames = `Click :one: to go back`;
  42. menus.helpAbout = `I'm a bot that aims to do a variety of things, one step at a time!
  43. Version = 0.0.1
  44.  
  45. My menu generator allows me to create dynamic menus within discord! Meaning no more clutter~
  46.  
  47. React with :one: to go back`;
  48.  
  49.  
  50. menus.s = {};
  51.  
  52. // Help menu structure.
  53. // I need to redo this in json later, but for now, this works.
  54. menus.s.help =
  55. {
  56. "main" : [menus.helpMain, ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣"], ['general', 'mods', 'admin', 'games', 'about']],
  57. "general" : [menus.helpGeneral, ["1⃣"], ['main']],
  58. "mods" : [menus.helpMods, ["1⃣"], ['main']],
  59. "admin" : [menus.helpAdmin, ["1⃣"], ['main']],
  60. "games" : [menus.helpGames, ["1⃣"], ['main']],
  61. "about" : [menus.helpAbout, ["1⃣"], ['main']]
  62. }
  63.  
  64. client.on("ready", () => {
  65. // This event will run if the bot starts, and logs in, successfully.
  66. console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
  67.  
  68. if (config.mode === "TESTING")
  69. {
  70. client.user.setActivity('in Debug Mode');
  71. } else {
  72. client.user.setActivity(`Running on ${client.guilds.size} servers`);
  73. }
  74.  
  75. logChannel = client.channels.get("599724398286733322");
  76. suggestChannel = client.channels.get("599724447880183808");
  77.  
  78. });
  79.  
  80. function suggestionMenu(msg)
  81. {
  82. msg.react("👍");
  83. msg.react("👎");
  84. }
  85.  
  86. async function helpMenu(channel)
  87. {
  88. //Default to our main menu ID.
  89. let menuID = menus.s.help['main'];
  90.  
  91. // Display our reaction's menu and dialogue.
  92. while (menuID !== -1)
  93. {
  94. let m = await channel.send(menuID[0]);
  95. let reactions = menuID[1];
  96.  
  97. for(let i = 0; i < reactions.length; i++)
  98. {
  99. await m.react(reactions[i]);
  100. }
  101.  
  102. // Create a filter.
  103. const filter = (reaction, user) => {
  104. return reactions.includes(reaction.emoji.name) && user.id !== client.user.id;
  105. }
  106.  
  107. // Gather out value.
  108. let x = await m.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
  109. .then(collected => {
  110. const reaction = collected.first();
  111. m.delete(10);
  112. return reactions.indexOf(reaction.emoji.name);
  113. })
  114. .catch(collected => {
  115. m.delete(10);
  116. return(-1);
  117. });
  118.  
  119. // Turn our value into something useable!
  120. if(x === -1)
  121. {
  122. menuID = x;
  123. } else if (x <= menuID[2].length)
  124. {
  125. menuID = menus.s.help[menuID[2][x]]; //Redirect the system to a new menu.
  126. }
  127. }
  128. }
  129.  
  130.  
  131. client.on("message", async message => {
  132. // This event will run on every single message received, from any channel or DM.
  133.  
  134. // It's good practice to ignore other bots. This also makes your bot ignore itself
  135. // and not get into a spam loop (we call that "botception").
  136. if(message.author.bot) return;
  137.  
  138. // Also good practice to ignore any message that does not start with our prefix,
  139. // which is set in the configuration file.
  140. if(message.content.indexOf(config.prefix) !== 0) return;
  141.  
  142. // Here we separate our "command" name, and our "arguments" for the command.
  143. // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
  144. // command = say
  145. // args = ["Is", "this", "the", "real", "life?"]
  146. const argsRaw = message.content.slice(config.prefix.length);
  147. const args = argsRaw.trim().split(/ +/g);
  148. const command = args.shift().toLowerCase();
  149.  
  150. logChannel.send("***COMMAND***: " + message.author + " sent command `" + message.content + "` in channel `" + message.channel.name + "` on server `" + message.channel.guild.name + "`");
  151.  
  152. // Let's go with a few common example commands! Feel free to delete or change those.
  153.  
  154. if(command === "help")
  155. {
  156. helpMenu(message.channel);
  157. }
  158.  
  159. if(command === "suggest")
  160. {
  161. message.channel.send("Thank you for your suggestion! It has been filed to be voted on.");
  162. suggestChannel.send("***SUGGESTION***: " + argsRaw.slice(command.length));
  163.  
  164. const m = await suggestChannel.send("Please Vote:");
  165. suggestionMenu(m);
  166.  
  167. }
  168.  
  169. if(command === "ping") {
  170. // Calculates ping between sending a message and editing it, giving a nice round-trip latency.
  171. // The second ping is an average latency between the bot and the websocket server (one-way, not round-trip)
  172. const m = await message.channel.send("Ping?");
  173. m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`);
  174. }
  175.  
  176. if(command === "say") {
  177. // makes the bot say something and delete the message. As an example, it's open to anyone to use.
  178. // To get the "message" itself we join the `args` back into a string with spaces:
  179. const sayMessage = args.join(" ");
  180. // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing.
  181. message.delete().catch(O_o=>{});
  182. // And we get the bot to say the thing:
  183. message.channel.send(sayMessage);
  184. }
  185.  
  186. if(command === "kick") {
  187. // This command must be limited to mods and admins. In this example we just hardcode the role names.
  188. // Please read on Array.some() to understand this bit:
  189. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some?
  190. if(!message.member.roles.some(r=>["Administrator", "Moderator"].includes(r.name)) )
  191. return message.reply("Sorry, you don't have permissions to use this!");
  192.  
  193. // Let's first check if we have a member and if we can kick them!
  194. // message.mentions.members is a collection of people that have been mentioned, as GuildMembers.
  195. // We can also support getting the member by ID, which would be args[0]
  196. let member = message.mentions.members.first() || message.guild.members.get(args[0]);
  197. if(!member)
  198. return message.reply("Please mention a valid member of this server");
  199. if(!member.kickable)
  200. return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
  201.  
  202. // slice(1) removes the first part, which here should be the user mention or ID
  203. // join(' ') takes all the various parts to make it a single string.
  204. let reason = args.slice(1).join(' ');
  205. if(!reason) reason = "No reason provided";
  206.  
  207. // Now, time for a swift kick in the nuts!
  208. await member.kick(reason)
  209. .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
  210. message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);
  211.  
  212. }
  213.  
  214. if(command === "set")
  215. {
  216. if(args.length > 1 && message.member.id === config.authorID)
  217. {
  218. if (args[0] === "status")
  219. {
  220. const newStat = argsRaw.slice(command.length + 7);
  221. message.channel.send("Alright, " + message.author + ", I've updated my status to `" + newStat + "`");
  222. client.user.setActivity(newStat);
  223. }
  224. } else if (message.member.id === config.authorID)
  225. {
  226. message.channel.send(`Sorry, I can't let you do that, ${message.author} ***bonk***`);
  227. }
  228. }
  229.  
  230. if(command === "ban") {
  231. // Most of this command is identical to kick, except that here we'll only let admins do it.
  232. // In the real world mods could ban too, but this is just an example, right? ;)
  233. if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) )
  234. return message.reply("Sorry, you don't have permissions to use this!");
  235.  
  236. let member = message.mentions.members.first();
  237. if(!member)
  238. return message.reply("Please mention a valid member of this server");
  239. if(!member.bannable)
  240. return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");
  241.  
  242. let reason = args.slice(1).join(' ');
  243. if(!reason) reason = "No reason provided";
  244.  
  245. await member.ban(reason)
  246. .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
  247. message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${reason}`);
  248. }
  249.  
  250. if(command === "purge") {
  251. // This command removes all messages from all users in the channel, up to 100.
  252.  
  253. // get the delete count, as an actual number.
  254. const deleteCount = parseInt(args[0], 10);
  255.  
  256. // Ooooh nice, combined conditions. <3
  257. if(!deleteCount || deleteCount < 2 || deleteCount > 100)
  258. return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
  259.  
  260. // So we get our messages, and delete them. Simple enough, right?
  261. const fetched = await message.channel.fetchMessages({limit: deleteCount});
  262. message.channel.bulkDelete(fetched)
  263. .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
  264. }
  265. });
  266.  
  267. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement