Discord is a well-known VoIP program that is widely used and widespread among gamers. Users can create channels for free and invite others to join. Some people use bots to listen to music, greet new users who have joined their channel, and so much more. This article explains how to create a bot for Discord. You will need to be familiar with programming, as the bot works thanks to JavaScript.
Steps
Part 1 of 6: Prepare the Computer
Step 1. Download Node.js from
Node.js is a free JavaScript runtime that you will need to create the bot. You can select the installer for Windows or macOS and the version you prefer. For this procedure, the LTS version is recommended.
Step 2. Start the installer
If you have a computer with a Windows operating system, all you have to do is click on the downloaded file to open the installer. A computer with a macOS system, on the other hand, requires you to unzip the file to find the installer application. Make sure you read all the chords as you progress.
Step 3. Create an account on Discord (optional)
If you don't already have it, you can create it at
Step 4. Log in to your Discord account and then to the channel
Open the Discord application on your computer and search for the channel in which you want to create the bot.
Part 2 of 6: Creating the Bot on Discord
Step 1. Visit https://discord.com/developers/applications/me using a browser
You should already be logged in through the application, but log in again if you are asked to do so. At this stage of the process, you will need to create an application that activates the bot. In addition to the bot, you will then create an app.
Step 2. Click on the blue New Application button
It is located on the right side of the browser. A window will appear, where you will be prompted to enter the name of the application.
Type the name of the application and click on "Create". You will need to choose a name that describes the bot's functions. For example, if the bot is for greeting people, you can name it "Greeterbot". However, it is possible that the name "Greeterbot" will cause an error report later, as it is quite popular. Therefore, add a series of numbers after the name, such as "Greeterbot38764165441"
Step 3. Click on Bot in the left menu
The icon depicts a puzzle piece.
Step 4. Click on Add Bot
This button is located in the section titled “Build-A-Bot”.
- Click on "Yes, do it!" in the pop-up to confirm the operation.
- If an error message appears because it is a particularly popular name, go to the application page and change it. For example, it is likely that the name "Music Bot" is already in use, so it would be useful to add some numbers to the end of the application name.
Step 5. Click on Click to Reveal Token
This button is located in the area dedicated to information on the bot. By clicking on it, you will see a series of letters and numbers.
Click on "Copy" to copy all the text. You can paste it on a post-it note, but make sure you have access to this code and don't give it to anyone. Anyone who owns it will be able to control the bot. This code will always be available to you in this section, should you need it
Part 3 of 6: Sending the Bot to the Server / Channel on Discord
Step 1. Click on General Information
This option is located in the left menu.
Step 2. Click Copy in the section titled Client ID
It is located more or less in the center of the page.
Step 3. Paste the ClientID into the following link:
discord.com/oauth2/authorize?&client_id=CLIENTID&scope=bot&permissions=8.
For example, if your ClientID is 000000000000000001, the URL would be the following:
Step 4. Paste the URL into the browser address bar
You will be redirected to a page where you can assign your bot to a channel.
- Click on the drop-down menu to view all your compatible channels.
- Click on "Authorize" to continue. You will receive a message, which will confirm that the bot has been transferred and that you can close the active tab.
Part 4 of 6: Programming the Bot
Step 1. Create a folder on the desktop for the bot code
In this folder you will need to save the files you will create.
- This code was provided by the site
- You can search the internet for bot codes you want, such as those that allow you to constantly play music. In this article, we use sample code for a bot that replies to any message that begins with an exclamation point ("!").
Step 2. Open a text editor
You can use predefined programs like Notepad (Windows) or TextEdit (Mac).
Step 3. Enter the following code:
{"Token": "Your bot token"}
Step 4. Save the file as “auth.json”
Make sure the file is not saved with a “.txt” extension.
Step 5. Open a new document
You can do this by pressing Ctrl + N (Windows) or ⌘ Cmd + N (Mac), or by clicking on "New" from the "File" tab.
Step 6. Type the following code:
{"Name": "greeter-bot", "version": "1.0.0", "description": "My First Discord Bot", "main": "bot.js", "author": "Your name "," Dependencies ": {}}
Step 7. Save the file as “package.json”
Make sure it is not saved with a “.txt” extension.
Step 8. Open a new document
You can do this by pressing Ctrl + N (Windows) or ⌘ Cmd + N (Mac). Alternatively, click on "New" from the "File" tab.
Step 9. Enter the bot code
For example, if you want to create a bot that responds to any message that begins with an exclamation point ("!"), Type the following code:
var Discord = require ('discord.io'); var logger = require ('winston'); var auth = require ('./ auth.json'); // Configure logger settings logger.remove (logger.transports. Console); logger.add (new logger.transports. Console, {colorize: true}); logger.level = 'debug'; // Initialize Discord Bot var bot = new Discord. Client ({token: auth.token, autorun: true}); bot.on ('ready', function (evt) {logger.info ('Connected'); logger.info ('Logged in as:'); logger.info (bot.username + '- (' + bot.id + ')');}); bot.on ('message', function (user, userID, channelID, message, evt) {// Our bot needs to know if it will execute a command // It will listen for messages that will start with `!` if (message.substring (0, 1) == '!') {var args = message.substring (1).split (''); var cmd = args [0]; args = args.splice (1); switch (cmd) {//! ping case 'ping': bot.sendMessage ({to: channelID, message: 'Pong!'}); break; // Just add any case commands if you want to.}}});
Step 10. Save the file as “bot.js”
Make sure it is not saved with a “.txt” extension.
Now, you can close the text editor
Part 5 of 6: Install the Bot Dependencies
Step 1. Open the Command Prompt window
On Windows, you can search for "cmd" in the search field of the "Start" menu. If you are using a Mac, you can search for "Command Prompt" in "Spotlight".
Step 2. Navigate to the bot folder you saved on your desktop
For example, you can type cd / Users / Default Desktop / Desktop / DiscordBotfoldername.
Step 3. Type npm install discord.io winston –save and press Enter
Installed Node.js, this line will automatically download the dependencies for the bot to the folder saved on the desktop.
Step 4. Type npm install and press Enter.
The code in question will make sure that there is nothing else to install for the bot to work.
At this point, you will have the bot code, and in the next part you can verify that it works
Part 6 of 6: Run the Bot
Step 1. Type node bot.js and hit Enter in the command prompt
If an error should appear, something has gone wrong.
Step 2. Type “! Intro” on Discord
This message must be typed in the channel where the bot is located. The sample code provided causes the bot to reply "Pong!" to messages starting with an exclamation point (“!”). So, to verify that the bot is actually working, type "! Intro" and wait for a response.
Step 3. Check the process if you don't get a response
If the bot does not respond to the "! Intro" message on Discord, please review this article and check the steps taken to make sure the bot has been configured correctly. Make sure that:
- Node.js has been installed successfully.
- The bot token has been entered correctly in the auth.json file.
- You are in the same channel as the bot.
- The bot is on the server.
- Your encoding is correct in the auth.json, bot.js and package.json files.
- All dependencies have been downloaded for the bot to work using the command prompt with Node.js installed.