Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load up the discord.js library
- const Discord = require("discord.js");
- // This is your client. Some people call it `bot`, some people call it `self`,
- // some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
- // this is what we're refering to. Your client.
- const client = new Discord.Client();
- // Here we load the config.json file that contains our token and our prefix values.
- const config = {
- "token" : "[Add your bot token here",
- "prefix" : "~",
- "mode" : "FULL",
- "authorID" : "270404393411674115" //Original Author's discord ID
- };
- let logChannel = "";
- let suggestChannel = "";
- const menus = {}
- menus.helpMain = `I see you need some help! What can I help you with?
- :one: General Commands.
- :two: Moderation
- :three: Administration/Maintenance
- :four: Games
- :five: About DungeonMeister
- To navigate, react with any number listed below.
- This menu will self-destruct after 30 seconds of inactivity :bomb:`;
- menus.helpGeneral = `\`~help\` - Displays this interactive help menu.
- \`~ping\` - Pong! returns the ping times of the bot.
- \`~suggest [suggestion]\` - Send a feature suggestion to the developer, it will be voted on to be implemented.
- React with :one: to go back`;
- menus.helpMods = `Click :one: to go back`;
- menus.helpAdmin = `\`~set [variable] [value]\` - Sets a value within the bot, such as the "playing" status.
- React with :one: to go back`;
- menus.helpGames = `Click :one: to go back`;
- menus.helpAbout = `I'm a bot that aims to do a variety of things, one step at a time!
- Version = 0.0.1
- My menu generator allows me to create dynamic menus within discord! Meaning no more clutter~
- React with :one: to go back`;
- menus.s = {};
- // Help menu structure.
- // I need to redo this in json later, but for now, this works.
- menus.s.help =
- {
- "main" : [menus.helpMain, ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣"], ['general', 'mods', 'admin', 'games', 'about']],
- "general" : [menus.helpGeneral, ["1⃣"], ['main']],
- "mods" : [menus.helpMods, ["1⃣"], ['main']],
- "admin" : [menus.helpAdmin, ["1⃣"], ['main']],
- "games" : [menus.helpGames, ["1⃣"], ['main']],
- "about" : [menus.helpAbout, ["1⃣"], ['main']]
- }
- client.on("ready", () => {
- // This event will run if the bot starts, and logs in, successfully.
- console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
- if (config.mode === "TESTING")
- {
- client.user.setActivity('in Debug Mode');
- } else {
- client.user.setActivity(`Running on ${client.guilds.size} servers`);
- }
- logChannel = client.channels.get("599724398286733322");
- suggestChannel = client.channels.get("599724447880183808");
- });
- function suggestionMenu(msg)
- {
- msg.react("👍");
- msg.react("👎");
- }
- async function helpMenu(channel)
- {
- //Default to our main menu ID.
- let menuID = menus.s.help['main'];
- // Display our reaction's menu and dialogue.
- while (menuID !== -1)
- {
- let m = await channel.send(menuID[0]);
- let reactions = menuID[1];
- for(let i = 0; i < reactions.length; i++)
- {
- await m.react(reactions[i]);
- }
- // Create a filter.
- const filter = (reaction, user) => {
- return reactions.includes(reaction.emoji.name) && user.id !== client.user.id;
- }
- // Gather out value.
- let x = await m.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
- .then(collected => {
- const reaction = collected.first();
- m.delete(10);
- return reactions.indexOf(reaction.emoji.name);
- })
- .catch(collected => {
- m.delete(10);
- return(-1);
- });
- // Turn our value into something useable!
- if(x === -1)
- {
- menuID = x;
- } else if (x <= menuID[2].length)
- {
- menuID = menus.s.help[menuID[2][x]]; //Redirect the system to a new menu.
- }
- }
- }
- client.on("message", async message => {
- // This event will run on every single message received, from any channel or DM.
- // It's good practice to ignore other bots. This also makes your bot ignore itself
- // and not get into a spam loop (we call that "botception").
- if(message.author.bot) return;
- // Also good practice to ignore any message that does not start with our prefix,
- // which is set in the configuration file.
- if(message.content.indexOf(config.prefix) !== 0) return;
- // Here we separate our "command" name, and our "arguments" for the command.
- // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
- // command = say
- // args = ["Is", "this", "the", "real", "life?"]
- const argsRaw = message.content.slice(config.prefix.length);
- const args = argsRaw.trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- logChannel.send("***COMMAND***: " + message.author + " sent command `" + message.content + "` in channel `" + message.channel.name + "` on server `" + message.channel.guild.name + "`");
- // Let's go with a few common example commands! Feel free to delete or change those.
- if(command === "help")
- {
- helpMenu(message.channel);
- }
- if(command === "suggest")
- {
- message.channel.send("Thank you for your suggestion! It has been filed to be voted on.");
- suggestChannel.send("***SUGGESTION***: " + argsRaw.slice(command.length));
- const m = await suggestChannel.send("Please Vote:");
- suggestionMenu(m);
- }
- if(command === "ping") {
- // Calculates ping between sending a message and editing it, giving a nice round-trip latency.
- // The second ping is an average latency between the bot and the websocket server (one-way, not round-trip)
- const m = await message.channel.send("Ping?");
- m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`);
- }
- if(command === "say") {
- // makes the bot say something and delete the message. As an example, it's open to anyone to use.
- // To get the "message" itself we join the `args` back into a string with spaces:
- const sayMessage = args.join(" ");
- // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing.
- message.delete().catch(O_o=>{});
- // And we get the bot to say the thing:
- message.channel.send(sayMessage);
- }
- if(command === "kick") {
- // This command must be limited to mods and admins. In this example we just hardcode the role names.
- // Please read on Array.some() to understand this bit:
- // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some?
- if(!message.member.roles.some(r=>["Administrator", "Moderator"].includes(r.name)) )
- return message.reply("Sorry, you don't have permissions to use this!");
- // Let's first check if we have a member and if we can kick them!
- // message.mentions.members is a collection of people that have been mentioned, as GuildMembers.
- // We can also support getting the member by ID, which would be args[0]
- let member = message.mentions.members.first() || message.guild.members.get(args[0]);
- if(!member)
- return message.reply("Please mention a valid member of this server");
- if(!member.kickable)
- return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
- // slice(1) removes the first part, which here should be the user mention or ID
- // join(' ') takes all the various parts to make it a single string.
- let reason = args.slice(1).join(' ');
- if(!reason) reason = "No reason provided";
- // Now, time for a swift kick in the nuts!
- await member.kick(reason)
- .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
- message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);
- }
- if(command === "set")
- {
- if(args.length > 1 && message.member.id === config.authorID)
- {
- if (args[0] === "status")
- {
- const newStat = argsRaw.slice(command.length + 7);
- message.channel.send("Alright, " + message.author + ", I've updated my status to `" + newStat + "`");
- client.user.setActivity(newStat);
- }
- } else if (message.member.id === config.authorID)
- {
- message.channel.send(`Sorry, I can't let you do that, ${message.author} ***bonk***`);
- }
- }
- if(command === "ban") {
- // Most of this command is identical to kick, except that here we'll only let admins do it.
- // In the real world mods could ban too, but this is just an example, right? ;)
- if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) )
- return message.reply("Sorry, you don't have permissions to use this!");
- let member = message.mentions.members.first();
- if(!member)
- return message.reply("Please mention a valid member of this server");
- if(!member.bannable)
- return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");
- let reason = args.slice(1).join(' ');
- if(!reason) reason = "No reason provided";
- await member.ban(reason)
- .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
- message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${reason}`);
- }
- if(command === "purge") {
- // This command removes all messages from all users in the channel, up to 100.
- // get the delete count, as an actual number.
- const deleteCount = parseInt(args[0], 10);
- // Ooooh nice, combined conditions. <3
- if(!deleteCount || deleteCount < 2 || deleteCount > 100)
- return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
- // So we get our messages, and delete them. Simple enough, right?
- const fetched = await message.channel.fetchMessages({limit: deleteCount});
- message.channel.bulkDelete(fetched)
- .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
- }
- });
- client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement