Seeking people who made custom discord bots? Liking their really cool commands and have no idea how they did it? Well no need to fear! This simple tutorial will show you how to make a discord bot in no time!
- You will need a Code Editor. I use VSC, some people prefer Sublime Text .
- I will be using Node.js LTS VERSION to run the bot and install the dependencies.
- Understanding of Javascript. If you don't have that then click --> HERE
- Understanding of JSON. If you don't have that then click --> HERE
- A Discord account. If you don't have that then click --> HERE
- An organised discord server. yes I mean organised because then you will know where to put things Click --> HERE if you need help!
My Source Codes are for reference use ONLY, so you can understand the layout!
Go to to discord developers, then create a new application. Then go on oauth and make a link. Go to bot and click on reveal token (don't show anyone this, its like a password). Then paste it in your config.json
Package.jsons is a json file where all the dependencies are kept, so the package name, version, folders.
- Create a package.json file using
npm init
in your terminal or manually making one.
{
"name": "Bot",
"version": "1.0.0",
"description": "My First Bot Made With Discord.js!",
"main": "index.js",
"dependencies": {
"discord.js": "^11.3.0"
},
"author": "Your Nickname Here"
}
Config.jsons are used to keep valuable information like tokens, and passwords, ids etc. IMPORTANT TO KEEP THIS SAFE
- Create a
config.json
file manually.
{
"token": "BOT-TOKEN-HERE",
"prefix": "PREFIX",
"ownerid": "YOUR-ID-HERE"
}
Index.js is the main frame to your bot! You can edit it so it can collect your commands from the commands
folder and make it fetch the js only file.
const Discord = require('discord.js'); // Require discord.js for your bot to communicate with the Discord API
const config = require('./config.json'); // Our config file
const client = new Discord.Client();
client.on('ready', () => { // When bot is online and ready
console.log(`I'm ready!`);
});
client.on("message", message => { // When the bot spots a message
if(message.author.bot) return; // Doesn't respond to bots
if(message.content.indexOf(config.prefix) !== 0) return; // Only responding to existing commands that start with "!"
const args = message.content.slice(config.prefix.length).trim().split(/ +/g); // Configure arguments for the commands
const command = args.shift().toLowerCase(); // Detect existing commands
//Commands
if(command === "ping") { // "!ping"
message.channel.send('Pong!'); // Send a message saying "Pong!"
}
});
client.login(config.token); // Log in with the bot token from our config file.
Open terminal in VSC or type cmd in search.
- npm init
- npm i
- npm i discord.js
- Using cd (change directory) navigate to your folder Eg : cd Programming/Bot
- Then use ls
- You will see all the files
- npm init
- npm i
- npm i discord.js
- Go to your discord server
- Invite the bot using your invite link that you made
- Then go back to Cmd or VSC
- Type
node index.js
The bot should turn on! - Now run PREFIX ping
You have successfully made your own discord bot. From now you can start adding more commands and understanding! Happy Coding!
Author: Yuma-Tsushima
what