How to Make a Discord Bot

Featured Create Discord Bot

Creating a custom Discord bot is a fun and engaging way to sustain the interest of your community server. When you invite your friends over to your channel, the bot will manage their interactions in your absence. For example, if a user is misbehaving, the bot can kick him or her out.

To do that, you have to acquaint yourself with some programming and steps to create your bot and add it to your server. The following guide simplifies what has to be done with easy-to-understand screenshots.

Also read: 15 Best Discord Bots to Improve Your Discord Server

Creating Discord Bot on Developer Portal

Log in to your Discord account and go to the developer portal. Here, you can create a new bot “application.”

Create Discord Bot New Application Press 1

Give your application a desired name and click “Create.”

Create Discord Bot New Application Enter Name 1

In the next step fill in some details regarding what this application is all about. You can choose an app icon. Remember to save the changes.

Create Discord Bot Application Name

Now add a bot using the “build-a-bot” feature of the portal.

Create Discord Bot Build New Bot

Give your consent to adding a bot to the app. The action is irrevocable.

Create Discord Bot Permission

After you complete the above steps, a wild bot is created. However, it is not ready to be shared yet. For that, you need to provide additional information.

Create Discord Bot Wild Bot Has Appeared

Make a checklist of what your bot can do. You should not give it administrator privileges, as then it can control your server. Feel free to let it mute or ban members, prioritize speakers, add reactions, embed links, manage nicknames, and much more. Each level of permission provided by you has its own unique ID you can see on the dashboard itself.

Create Discord Bot List Of Permissions

Also read: 9 Best Discord Gaming Bots You Must Add to Your Server

Creating the Code for Your Discord Bot

If you are a programmer, you will want to modify the bot’s functions quite a bit. This demonstration uses node.js, a JavaScript runtime environment. Once installed for Windows, you may want to install “additional tools,” which can be done directly from the command terminal. It will install Chocolatey, Visual Studio, and other programs in Windows Powershell.

Create Discord Bot Install Chocolatey

Download and install Node.js for Windows x64 and then run the following specific program from the Start menu. It’s a Node.js command prompt. (Don’t run the other Node.js application file, as it has a different use.)

Create Discord Bot Nodejs Command Promptjpg

Once the environment has been set up for using Node.js, you will have to install “discord.js with voice support” using the following code.

npm install discord.js @discordjs/opus
Create Discord Bot Install Discord.js On Npm

You should see a success status for the number of packages created.

Create Discord Bot Installed Discord.js

Install nodemon as shown below.

npm i -g nodemon
Create Discord Bot Add Nodemon Code

Go back to your Discord bot on your developer portal webpage. Click the icon for “click to reveal token,” and it will display an alphanumeric key, which is your private Admin. Don’t share the token with anyone, as it is easily hackable.

Create Discord Bot Token

Check the code example shown at the official Discord site.

const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
    if (msg.content === 'ping') {
        msg.reply('pong');
    }
});
client.login('token');

Instead of a token in the last line of code, copy-paste your own Discord bot token.

Create Discord Bot Add Token Atom Editor

Save the file as “Index.js” in any folder which is directly accessible from the Command prompt. It can have any name as long as it is a .js file.

Create Discord Bot Add Save Indexjs File

Now, to run the bot, enter the following code.

nodemon --inspect "file name".js

When it’s ready, the Node.js will then log you into your Discord API. There is also an editor mode in Node.js which you can access from .help option. This is where you can introduce further edits to your bot.

Create Discord Bot Logging In As Bot

Also read: What Are Stage Channels and How to Use Them in Discord

Adding the Bot to Your Server

Once your bot has been created, you will want to add it to your Discord server. For that, you will need a link such as the following:

https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot

The “client ID” is found in General information under the Application where you have saved the bot.

Create Discord Bot Go To Applications

In the below screen, you can see the client ID for the bot that was created in the first section.

Create Discord Bot Client Id

Open a browser and enter the link shared above. Simply replace the client ID with yours. You can choose the server where you can add the bot.

Create Discord Bot Add Bot To Server

If the bot is successfully created, you will see an “authorized” message which shows the app has been connected to your Discord server. If you have the Discord server installed for Windows, you should see an alert in the system tray as shown here.

Create Discord Bot Bot Added To Server

The created bot has been successfully added to the Discord server.

Create Discord Bot Bot Visible In Server

Discord bots are an interactive means to build interest in your server. For more information on working with custom Discord bots, refer to this official manual.

Have you created your own Discord bot? What was its purpose? Please share your ideas in the comments.

Also read: How to Install Discord on Ubuntu Linux

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sayak Boral Avatar

Read next

Suzanne Simard sealed paper birch and Douglas fir seedlings inside plastic bags, fed them carbon-14 and carbon-13 dioxide, and nine days later found carbon had crossed between species through fungal threads in the British Columbia soil beneath her boots
A species of jellyfish called Turritopsis dohrnii can revert its adult cells back to a juvenile polyp stage when injured or starving, effectively restarting its life cycle, and biologists have so far failed to identify any natural limit to how many times it can do this.
A Japanese man named Jiroemon Kimura, who lived to 116, was born in 1897 when Queen Victoria still ruled and died in 2013, meaning a single human life personally overlapped with the invention of the airplane, the atomic bomb, the internet, and Instagram
The Hollywood sign originally read HOLLYWOODLAND when it was built in 1923 as a real estate advertisement for a housing development, and it was only meant to stand for 18 months, but nobody ever got around to taking it down and the city eventually adopted it as a landmark
Almost all of the world’s internet traffic does not travel by satellite but through fibre-optic cables lying on the ocean floor, a hidden web of wires crossing the deepest parts of the sea to connect the continents.
People who flip their phone face down on every table aren’t being secretive. They figured out that staying interruptible meant handing their time to whoever rang first
Twitch vs. Facebook Gaming vs. YouTube Gaming: What’s the Best Live Game Streaming Platform?
Chrome Extensions Ownership Transfer is a Direct Threat to You: How to Stay Safe