├── README.md ├── botconfig.json ├── commands ├── moderation │ ├── ban.js │ ├── clear.js │ ├── kick.js │ └── unban.js └── user │ ├── info.js │ └── testembeds.js ├── config.json ├── events ├── client │ ├── message.js │ └── ready.js └── guild │ └── readme.txt ├── handlers ├── command.js └── events.js ├── index.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # tutorial-bot 2 | Discord.js v12 Basic Bot with Basic Bot Commands 3 | 4 | YouTube: https://www.youtube.com/channel/UC1zfP7GYvB2LD-49TQcYInQ?view_as=subscriber 5 | Discord: https://www.discord.gg/3HCefjF 6 | Oblivion Bot Invite: https://bradybots.com/ 7 | 8 | 9 | YouTube Episode 1: 10 | - Info command 11 | - Whois command 12 | 13 | 14 | YouTube Episode 2: 15 | - Clear command 16 | 17 | YouTube Episode 3: 18 | (COMPLETE MAKEOVER) 19 | - Command Handler 20 | - Event Handler 21 | - Message Event 22 | - Ready Event 23 | - Info Command 24 | - Clear Command 25 | -------------------------------------------------------------------------------- /botconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "token": "" 3 | } 4 | -------------------------------------------------------------------------------- /commands/moderation/ban.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = { 4 | config: { 5 | name: `ban`, 6 | aliases: [`ban`] 7 | }, 8 | run: async (bot, message, args) => { 9 | message.delete() 10 | if(!message.member.hasPermission(`BAN_MEMBERS`)) return message.reply(`You do not have permission to use this command.`) 11 | let banMember = message.mentions.members.first(); 12 | if(!banMember) return message.reply(`You did not mention a user to ban`) 13 | let banreason = args.slice(1).join(" "); 14 | if(!banreason) banreason = `No reason specified`; 15 | message.guild.members.ban(banMember, {reason: `Staff: ${message.author.tag} || Reason: ${banreason}`}) 16 | message.reply(`${banMember} has been banned by ${message.author.tag} for ${banreason}.`) 17 | } 18 | } -------------------------------------------------------------------------------- /commands/moderation/clear.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = { 4 | config: { 5 | name: `clear`, 6 | aliases: [`purge`, `clear`] 7 | }, 8 | run: async (bot, message, args) => { 9 | message.delete() 10 | if(!message.member.hasPermission(`KICK_MEMBERS`)) return message.reply(`You do not have permission to use this command.`).then(m => (m.delete({timeout: 10000}))); 11 | let clearamount = args[0]; 12 | if(isNaN(clearamount)) return message.reply(`Please do a number value to clear.`).then(m => (m.delete({timeout: 10000}))); 13 | if(clearamount >= 100) clearamount = 99; 14 | if(clearamount <= 0) return message.reply(`Please choose a number greater than **0** and less than **1**`) 15 | message.channel.send(`⚠ Clearing Messages.. Please Wait! ⚠️`).then(msg => msg.delete({timeout: 2000})); 16 | setTimeout(async () => { 17 | await message.channel.bulkDelete(clearamount); 18 | }, 1000) 19 | } 20 | } -------------------------------------------------------------------------------- /commands/moderation/kick.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = { 4 | config: { 5 | name: `kick`, 6 | aliases: [`kick`] 7 | }, 8 | run: async (bot, message, args) => { 9 | message.delete() 10 | if(!message.member.hasPermission('KICK_MEMBERS')) return message.reply(`You do not have permission`); 11 | let kuser = message.mentions.members.first() 12 | if(!kuser) return console.log(`no user stated to be kicked.`) 13 | let kreason = args.slice(1).join(" "); 14 | if(!kreason) kreason = `No reason specified.`; 15 | kuser.kick(`Staff: ${message.author.tag} || Reason: ${kreason}`) 16 | message.reply(`${kuser} has been kicked by ${message.author.tag} for ${kreason}.`) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /commands/moderation/unban.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = { 4 | config: { 5 | name: `unban`, 6 | aliases: [`unban`], 7 | }, 8 | run: async (bot, message, args) => { 9 | // Deleting the command message 10 | message.delete() 11 | // Checking if they are staff 12 | if(!message.member.hasPermission(`BAN_MEMBERS`)) return message.reply(`You do not have permission to use this command.`) 13 | let serverm = message.guild.members; 14 | // Finding the ID mentioned in the arugument 15 | if(isNaN(args[0])) return message.reply(`Please state a valid USER id.`) 16 | let bannedMember = bot.users.fetch(args[0]); 17 | if(!bannedMember) return message.reply(`There was no user to Unban.`) 18 | // Unbanning the person via ID 19 | serverm.unban(bannedMember); 20 | // Wrapping it up with a bow 21 | await message.reply(`**${bannedMember.id}** has been unbanned from the discord by ${message.author.tag}.`) 22 | } 23 | } -------------------------------------------------------------------------------- /commands/user/info.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = { 4 | config: { 5 | name: `info`, 6 | aliases: [`information`, `info`] 7 | }, 8 | run: async (bot, message, args) => { 9 | message.delete() 10 | let info1 = `v1.0.0` 11 | let info2 = `Node v12` 12 | let info3 = `Discord.js v12` 13 | let info4 = `Brady#1234` 14 | 15 | let embed = new MessageEmbed() 16 | .setTitle(`Bot Information`) 17 | .setColor(`DARK_RED`) 18 | .setThumbnail(bot.user.displayAvatarURL()) 19 | .setFooter(message.guild.name) 20 | .setTimestamp() 21 | .addField(`Version:`, info1, true) 22 | .addField(`Node Version:`, info2, true) 23 | .addField(`Coded in:`, info3, true) 24 | .setDescription(`Bot Developed by: ${info4}`) 25 | message.channel.send(embed).then(m => (m.delete({timeout: 10000}))); 26 | } 27 | } -------------------------------------------------------------------------------- /commands/user/testembeds.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = { 4 | config: { 5 | name: `testembeds`, 6 | aliases: [`testembeds`, `testembeds`], 7 | }, 8 | run: async (bot, message, args) => { 9 | 10 | let embed = new MessageEmbed() 11 | .setColor(`RED`) 12 | .setTitle(`Testing out Embed Mesasges`) 13 | .setURL(`https://google.com`) 14 | .setAuthor(`Testing out Embed Messages`, bot.user.displayAvatarURL()) 15 | .setDescription(`This a Brady Bots Development Tutorial on how to make and use embeded messages using discord.js v12 and node v12.`) 16 | .addFields( 17 | { name: `Test 1`, value: `Brady#1234` }, 18 | { name: `Test 2`, value: `\u200B` }, 19 | { name: `Test 3`, value: `Brady Bots Development`, inline: true}, 20 | { name: `Test 4`, value: `Oblivion Bot Is Awesome!`, inline: true}, 21 | ) 22 | .addField(`This is a test for a single add Field`, `Testing 1 2 3`, false) 23 | .setImage(bot.user.displayAvatarURL()) 24 | .setTimestamp() 25 | .setThumbnail(bot.user.displayAvatarURL()) 26 | .setFooter(`Brady Bots Development 2020`, bot.user.displayAvatarURL()) 27 | 28 | message.channel.send(embed); 29 | } 30 | } -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix": "!" 3 | } 4 | -------------------------------------------------------------------------------- /events/client/message.js: -------------------------------------------------------------------------------- 1 | const { Discord, MessageEmbed } = require("discord.js"); 2 | const { fs } = require('fs'); 3 | const { prefix } = require('../../config.json'); 4 | 5 | module.exports = async (bot, message) => { 6 | if(message.author.bot || message.channel.type === "dm" || !message.content.startsWith(prefix)) return; 7 | const args = message.content.slice(prefix.length).trim().split(/ +/g); 8 | const cmd = args.shift().toLowerCase(); 9 | let commandfile = bot.commands.get(cmd) || bot.commands.get(bot.aliases.get(cmd)); 10 | if(commandfile) commandfile.run(bot, message, args); 11 | } -------------------------------------------------------------------------------- /events/client/ready.js: -------------------------------------------------------------------------------- 1 | const { Discord, MessageEmbed } = require('discord.js'); 2 | 3 | module.exports = async (bot) => { 4 | console.log(`${bot.user.tag} is now online.`) 5 | } -------------------------------------------------------------------------------- /events/guild/readme.txt: -------------------------------------------------------------------------------- 1 | This is to fix the Scandir error. 2 | - Brady 3 | -------------------------------------------------------------------------------- /handlers/command.js: -------------------------------------------------------------------------------- 1 | const { readdirSync } = require(`fs`); 2 | 3 | module.exports = (bot) => { 4 | const load = dirs => { 5 | const commands = readdirSync(`./commands/${dirs}/`).filter(d => d.endsWith(`.js`)); 6 | for(let file of commands) { 7 | let pull = require(`../commands/${dirs}/${file}`); 8 | bot.commands.set(pull.config.name, pull); 9 | if(pull.config.aliases) pull.config.aliases.forEach(a => bot.aliases.set(a, pull.config.name)); 10 | console.log(`Command | ${pull.config.name} has loaded`) 11 | } 12 | }; 13 | ["user", "moderation"].forEach(x => load(x)); 14 | } -------------------------------------------------------------------------------- /handlers/events.js: -------------------------------------------------------------------------------- 1 | const { readdirSync } = require('fs'); 2 | 3 | module.exports = (bot) => { 4 | const load = dirs => { 5 | const events = readdirSync(`./events/${dirs}/`).filter(d => d.endsWith(`.js`)); 6 | for (let file of events) { 7 | const evt = require(`../events/${dirs}/${file}`); 8 | let eName = file.split(`.`)[0]; 9 | bot.on(eName, evt.bind(null, bot)); 10 | console.log(`Event | ${eName} has loaded.`) 11 | } 12 | }; 13 | ["client", "guild"].forEach(x => load(x)); 14 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { Client, Collection } = require('discord.js'); 2 | const bot = new Client(); 3 | const { token } = require(`./botconfig.json`); 4 | const { prefix } = require(`./config.json`); 5 | [`aliases`, `commands`].forEach(x => bot[x] = new Collection()); 6 | ["command", "events"].forEach(x => require(`./handlers/${x}`)(bot)); 7 | bot.login(token); 8 | 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tutorial-bot", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Brady", 10 | "license": "ISC", 11 | "dependencies": { 12 | "discord.js": "^12.2.0", 13 | "nodemon": "^2.0.4" 14 | } 15 | } 16 | --------------------------------------------------------------------------------