├── README.md ├── commands └── example.js ├── config.json ├── index.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # DiscordJS_Template 2 | Hey guys! Thought I would add the template I use for whenever I start a new bot. It has a simple command handler and example command! Join the Discord Server for help with this! 3 | 4 | Step 1) 5 | 6 | Download or git clone the files to your local machine. 7 | 8 | 9 | Step 2) 10 | 11 | Change token in config.json file 12 | 13 | Step 3) 14 | 15 | Run "npm i" in command prompt/terminal/powershell in the directory where the files are located. 16 | 17 | Step 4) 18 | 19 | Add your own commands and have fun! 20 | 21 | 22 | 23 | Like I said in the description, join our Discord Server for any questions. Heres the link http://www.discord.tscforum.com 24 | -------------------------------------------------------------------------------- /commands/example.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | 3 | module.exports.run = async (bot, message, args) => { 4 | //this is where the actual code for the command goes 5 | await message.delete() 6 | return message.reply("Hi! I'm an example command").then(m => m.delete(10000)) 7 | } 8 | //name this whatever the command name is. 9 | module.exports.help = { 10 | name: "example" 11 | } 12 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix": "!", 3 | "token": "setmeplease" 4 | } 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js") 2 | const config = require("./config.json") 3 | const bot = new Discord.Client(); 4 | const fs = require("fs"); 5 | bot.commands = new Discord.Collection(); 6 | if(config.token === "setmeplease") return console.log("Set your token up! Go to https://www.discordapp.com/developers and generate a token from a bot user."); 7 | 8 | fs.readdir("./commands/", (err, files) => { 9 | 10 | if(err) console.log(err); 11 | 12 | let jsfile = files.filter(f => f.split(".").pop() === "js"); 13 | if(jsfile.length <= 0){ 14 | console.log("Couldn't find commands."); 15 | return; 16 | } 17 | 18 | jsfile.forEach((f, i) =>{ 19 | let props = require(`./commands/${f}`); 20 | console.log(`${f} loaded!`); 21 | bot.commands.set(props.help.name, props); 22 | }); 23 | 24 | }); 25 | 26 | 27 | bot.on("ready", () => { 28 | console.log(bot.user.username + " is online.") 29 | }); 30 | 31 | bot.on("message", async message => { 32 | //a little bit of data parsing/general checks 33 | if(message.author.bot) return; 34 | if(message.channel.type === 'dm') return; 35 | let content = message.content.split(" "); 36 | let command = content[0]; 37 | let args = content.slice(1); 38 | let prefix = config.prefix; 39 | 40 | 41 | //checks if message contains a command and runs it 42 | let commandfile = bot.commands.get(command.slice(prefix.length)); 43 | if(commandfile) commandfile.run(bot,message,args); 44 | }) 45 | 46 | 47 | bot.login(config.token) 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discordjs_template", 3 | "version": "1.0.0", 4 | "description": "A template for Discordjs with command handler and example file.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Ned from {TheSourceCode}", 10 | "license": "ISC", 11 | "dependencies": { 12 | "discord.js": "^11.3.2", 13 | "fs": "0.0.1-security", 14 | "ms": "^2.1.1" 15 | } 16 | } 17 | --------------------------------------------------------------------------------