How to Make a Discord Bot

Discord is a chat platform, which is specially made for video gamers.  This software is available for PC,  MAC operating system,  Linux,  Android, and iOS, but it is recommended to use the app.

how to make discord bot

What is Discord Bot and Its Uses

Discord bot is the best way to increase the productivity of the server, which helps you to schedule events, sending notifications, get important data, and many more. This is one of the most promising features of Discord, which is used frequently.

Basically Discord bots are automated tasks, which performed on your discord server after specific events occurring. Like sending a welcome message to new members, server moderation, view information about your server or member, leveling system of discord room.

Now talking about how to use these bots, First thing you have to decide what functionality you want on your server. For example, you want to add a flare on the server or need a moderation bot, etc. Many readymade discord bots are available on the internet, a recommended website is top.gg. Here you can find many categorized discord bot, just invite it on your server.

How to Make a Discord Bot

Discord has an API, via this, we can create any custom bot, For this, you need some programming skills, it’s not for everyone. Let’s start with the initial process to create a discord bot.

1. First visit to the discord developer portal. Here you need to create New Application, just name it as you want to identify.

discord developer account

2. Now you get the Client ID and Secret key, note it down, we need it later. Make sure that do not reveal these keys to anyone, otherwise your bot will be hacked.

custom discord bot keys

3. Now add a bot user to your application, via click on the ‘Add Bot’ button. This action is irrevocable so choose wisely.

add discord bot

4. After adding bot user, you got the token, click to reveal token and note it down. This is important, so don’t share it with anyone. Enable PUBLIC BOT option, so this bot can be added by anyone, Or you can keep this bot private.

get bot token

At the same screen below, all the bot permissions are mentioned, you can select any one as per your discord bot requirement.

custom bot permissions

The above process is for creating a discord bot online via browser app, next we are showing to create custom code for the bot to add more functionality in it and install on your server. So let’s start coding for that…

Start coding to create Discord Bot in PHP:

We are using PHP programming language to create discord bot, for this, you need basic knowledge of it and a composer (https://getcomposer.org/) installed on your server.

Note: PHP version must be 5.6 or above, we recommend to use PHP 7.X.

Step a: Create a folder on your server via composer, let’s create it ‘NewBot’ folder using this command:

$ mkdir NewBot && cd NewBot

Then initialize the composer via this command:

$ composer init

Now we need DiscordPHP into composer project, for this execute this command :

composer require team-reflex/discord-php

This command will install the latest version of DiscordPHP

Step b: Now create a run.php file inside root ‘NewBot’ folder, that you just created and add below code in it.

run.php

Now add your Bot Token in run.php file, which we got in above Step 4.

Step c: Now do invite this custom bot into your channel, for this use this web URL in your browser:

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

Replace CLIENTID with your application client ID value and execute this URL. This will prompt a window to add bot to the server, Pick any server and authorize it.

add custom bot to server

Note: You can add this bot only on the channels that you are an admin.

Step d: To start this bot and make it online, go on cmd, and write the correct path of the NewBot folder and type “php run.php” command.

This will start discord bot accessible online on your channel.

Once these all steps are done, you can send this link to your friends to add this bot on their discord server too.

That’s it. We have shown a basic example of the bot, you can add more functionality via adding more code in run.php file. Such as display channel member information, auto-reply of specific message, etc.

Hope this tutorial helps you create your first Discord Bot successfully. Thanks

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish

Leave a Comment

Your email address will not be published. Required fields are marked *