├── .gitattributes ├── config.json ├── .gitignore ├── package.json ├── README.md └── bot.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "token": "put_your_token_here", 3 | "prefix": "+" 4 | } 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | config.json 3 | package-lock.json 4 | yarn.lock 5 | npm-debug.log 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discordjs-moderation-bot", 3 | "version": "1.0.0", 4 | "description": "A small Discord bot, without a command handler ", 5 | "main": "bot.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/choppymaster/discord.js-moderation-bot.git" 12 | }, 13 | "keywords": [ 14 | "bot", 15 | "discord" 16 | ], 17 | "author": "root admin", 18 | "license": "ISC", 19 | "bugs": { 20 | "url": "https://github.com/choppymaster/discord.js-moderation-bot/issues" 21 | }, 22 | "homepage": "https://github.com/choppymaster/discord.js-moderation-bot#readme" 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A small Discord moderation bot, without a command handler 2 | 3 | 4 | # Getting started (For people who aren't used to Discord.js) 5 | 6 | 7 | ### Requirements 8 | * Node.js 9 | * A code editor (visual studio code, atom, notepad++ etc) 10 | * Git 11 | 12 | ### Step zero, making a Discord bot account 13 | Go to https://discord.com/developers and make an application. After creating your application, you should have the option to create a bot user. 14 | 15 | ### Step one, making the folder 16 | Make a folder for which your bot's coding will be in 17 | 18 | 19 | ### Step two, opening powershell 20 | Do shift + right click and select open powershell (or cmd depending on your PC) 21 | ![Step two](https://i.imgur.com/1quX9nB.png "Step two") 22 | 23 | 24 | ### Step three, initiating, type `npm init` 25 | 26 | ### Step four, installing Discord.js 27 | Now, you should type `npm install discord.js`, we are installing the discord.js module. Note: This will make a file called `package-lock.json` and a directory called `node_modules`, please don't delete that. 28 | 29 | ### Step five (I), getting your bot's token 30 | Get your bots token. Reminder, bot tokens are key information that gives complete access to your bot. 31 | 32 | ### Step five (II), config.json 33 | Place your bot's token **between** the quotation marks, you can also edit the prefix if you'd like. 34 | ![Step six](https://i.imgur.com/dy7OSYW.png "Step six") 35 | 36 | ### Step six, running your bot 37 | Run your bot by typing `node bot` into your powershell/cmd 38 | 39 | ### Step seven, adding your bot to your server 40 | Use this link and replace **client_id_here** with your actual client ID 41 | https://discordapp.com/api/oauth2/authorize?client_id=client_id_here&permissions=0&scope=bot 42 | # And your bot is running! 43 | Enjoy the bot, updates are frequent so always return to replace your `bot.js` with the newest one. 44 | 45 | --- 46 | 47 | ### Any errors? 48 | If you'd like to come to me personally, join the [support server](https://discord.gg/t2nV9kBnch) 49 | 50 | Also a big thank you to the contributors for correcting small errors and adding help to the bot. 51 | -------------------------------------------------------------------------------- /bot.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js") 2 | const bot = new Discord.Client({disableMentions: 'everyone'}) 3 | const config = require("./config.json") 4 | 5 | 6 | bot.on("ready", () => { 7 | console.log("Loaded up!") 8 | }); 9 | 10 | bot.on("message", message => { 11 | if (message.author.bot) return; 12 | if (message.content.indexOf(config.prefix) !== 0) return; 13 | 14 | const args = message.content.slice(config.prefix.length).trim().split(/ +/g); 15 | const command = args.shift().toLowerCase() 16 | 17 | if (command === "help") { 18 | const helpEmbed = new Discord.MessageEmbed() 19 | .setTitle(`${bot.user.username}'s commands`) 20 | .setDescription(`**Prefix:** ${config.prefix}`) 21 | .addField(`\`ping\``, `Check your bot's ping`) 22 | .addField(`\`kick\``, `Usage: **${config.prefix}kick [@User]**\n**${config.prefix}kick [@User][Reason]**`) 23 | .addField(`\`ban\``, `Usage: **${config.prefix}ban [@User]**\n**${config.prefix}ban [@User][Reason]**`) 24 | .addField(`\`add\``, `Adds a role to a user \nUsage: **${config.prefix}add [@User] [Role]**`) 25 | .addField(`\`remove\``, `Removes a role from a user \nUsage: **${config.prefix}remove [@User] [Role]**`) 26 | .addField(`\`purge\``, `Clears a number of messages between 2 or 100 \nUsage: **${config.prefix}purge [number]**`) 27 | .addField(`\`rps\``, `Play rock paper scissors`) 28 | .addField(`\`say\``, `Have the bot say something`) 29 | message.channel.send(helpEmbed) 30 | } 31 | 32 | if (command === "ping") { 33 | message.channel.send(`Pong **(${Date.now() - message.createdTimestamp}ms)**`) 34 | } 35 | 36 | if (command === "kick") { 37 | if (!message.member.hasPermission('KICK_MEMBERS')) 38 | return message.channel.send("Insufficient permissions (Requires permission `Kick members`)").then(msg => { 39 | msg.delete({ timeout: 30000 }) 40 | }) 41 | const member = message.mentions.members.first(); 42 | if (!member) 43 | return message.channel.send("You have not mentioned a user").then(msg => { 44 | msg.delete({ timeout: 30000 }) 45 | }) 46 | if (!member.kickable) 47 | return message.channel.send("This user is unkickable").then(msg => { 48 | msg.delete({ timeout: 30000 }) 49 | }) 50 | const reason = args.slice(1).join(" ") 51 | if (member) { 52 | if (!reason) return member.kick().then(member => { 53 | message.channel.send(`${member.user.tag} was kicked, no reason was provided`); 54 | }) 55 | 56 | if (reason) return member.kick().then(member => { 57 | message.channel.send(`${member.user.tag} was kicked for ${reason}`); 58 | }) 59 | } 60 | } 61 | 62 | if (command === "ban") { 63 | if (!message.member.hasPermission('BAN_MEMBERS')) 64 | return message.channel.send("Insufficient permissions (Requires permission `Ban members`)").then(msg => { 65 | msg.delete({ timeout: 30000 }) 66 | }) 67 | const member = message.mentions.members.first(); 68 | if (!member) 69 | return message.channel.send("You have not mentioned a user").then(msg => { 70 | msg.delete({ timeout: 30000 }) 71 | }) 72 | if (!member.bannable) 73 | return message.channel.send("This user is unbannable").then(msg => { 74 | msg.delete({ timeout: 30000 }) 75 | }) 76 | const reason = args.slice(1).join(" ") 77 | if (member) { 78 | if (!reason) return member.ban().then(member => { 79 | message.channel.send(`${member.user.tag} was banned, no reason was provided`); 80 | }) 81 | 82 | if (reason) return member.ban(reason).then(member => { 83 | message.channel.send(`${member.user.tag} was banned for ${reason}`); 84 | }) 85 | } 86 | } 87 | 88 | if (command === "add") { 89 | if (!message.member.hasPermission('MANAGE_ROLES')) 90 | return message.channel.send("Insufficient permissions (Requires permission `Manage roles`)").then(msg => { 91 | msg.delete({ timeout: 30000 }) 92 | }) 93 | const member = message.mentions.members.first() 94 | if (!member) 95 | return message.channel.send("You have not mentioned a user").then(msg => { 96 | msg.delete({ timeout: 30000 }) 97 | }) 98 | const add = args.slice(1).join(" ") 99 | if (!add) 100 | return message.channel.send("You have not specified a role").then(msg => { 101 | msg.delete({ timeout: 30000 }) 102 | }) 103 | const roleAdd = message.guild.roles.cache.find(role => role.name === add) 104 | if (!roleAdd) 105 | return message.channel.send("This role does not exist").then(msg => { 106 | msg.delete({ timeout: 30000 }) 107 | }) 108 | if (member.roles.cache.get(roleAdd.id)) 109 | return message.channel.send(`This user already has the ${add} role`).then(msg => { 110 | msg.delete({ timeout: 30000 }) 111 | }) 112 | member.roles.add(roleAdd.id).then((member) => { 113 | message.channel.send(`${add} added to ${member.displayName}`) 114 | }) 115 | } 116 | 117 | if (command === "remove") { 118 | if (!message.member.hasPermission('MANAGE_ROLES')) 119 | return message.channel.send("Insufficient permissions (Requires permission `Manage roles`)").then(msg => { 120 | msg.delete({ timeout: 30000 }) 121 | }) 122 | const member = message.mentions.members.first() 123 | if (!member) 124 | return message.channel.send("You have not mentioned a user").then(msg => { 125 | msg.delete({ timeout: 30000 }) 126 | }) 127 | const remove = args.slice(1).join(" ") 128 | if (!remove) 129 | return message.channel.send("You have not specified a role").then(msg => { 130 | msg.delete({ timeout: 30000 }) 131 | }) 132 | const roleRemove = message.guild.roles.cache.find(role => role.name === remove) 133 | if (!roleRemove) 134 | return message.channel.send("This role does not exist").then(msg => { 135 | msg.delete({ timeout: 30000 }) 136 | }) 137 | if (!member.roles.cache.get(roleRemove.id)) 138 | return message.channel.send(`This user does not have the ${remove} role`).then(msg => { 139 | msg.delete({ timeout: 30000 }) 140 | }) 141 | member.roles.remove(roleRemove.id).then((member) => { 142 | message.channel.send(`${remove} removed from ${member.displayName}`) 143 | }) 144 | } 145 | 146 | if (command === "say") { 147 | const text = args.join(" ") 148 | if(!text) return message.channel.send("You have not specified something to say").then(msg => { 149 | msg.delete({ timeout: 30000 }) 150 | }) 151 | message.channel.send(text) 152 | 153 | } 154 | 155 | if (command === "purge") { 156 | if(!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send("Insufficient permissions (requires permission `Manage messages`)").then(msg => { 157 | msg.delete({ timeout: 30000 }) 158 | }) 159 | const number = args.join(" ") 160 | if(!number) return message.channel.send("You haven't specified a number to purge").then(msg => { 161 | msg.delete({ timeout: 30000 }) 162 | }) 163 | message.channel.bulkDelete(number).catch(console.error) 164 | 165 | } 166 | 167 | if (command === "rps") { 168 | const options = [ 169 | "rock :shell: ", 170 | "paper :newspaper2:", 171 | "scissors :scissors: " 172 | ] 173 | const option = options[Math.floor(Math.random() * options.length)] 174 | message.channel.send(`You got ${option}`) 175 | } 176 | 177 | }); 178 | 179 | bot.login(config.token) 180 | --------------------------------------------------------------------------------