How To Make a Discord Bot: Overview & Tutorial
Heard of it before? Do you know what is a discord bot? How to make a Discord bot? Firstly, you need to learn what is a Discord.
Discord is a real-time messaging platform. It enables you to text during gaming and its all-in-one-voice feature makes it amazing. Discord has some mind-blowing features and that too with a user-friendly interface. Because of such flexibility, Discord continues to grow at a rapid pace and is popular now even among those who don’t have any interest in video games.
Discord experienced an unprecedented rise in its user-base between 2017 and 2018 when its user base reached 130 million mark. Do you know why its interesting? Because with that, Discord now has twice as many daily users as Slack!
Discord provides robust support for programmable bots. And these programmable bots help the developers to integrate Discord with the world outside, hence improving user experience. Generally, bots are ubiquitous on Discord and they provide various services including assistance, music, internet searches and much more!
By the end of this blog, you’ll be able to write a simple discord bot in JavaScript. We’ll show you how to make a Discord bot on android and on Mac as well.
Also read: HOW TO USE OBS STUDIO (A-Z GUIDE)
How To Make a Discord Music Bot
It is necessary to have permission before you install a Discord music bot. For that, you must be a server owner or at least have administrator rights. However, if you don’t have any of these, you’ll have to ask the existing owner. Click on server settings to find out what specific permissions your role has on Discord!
On the settings page, click Roles – that is on left – and then right, look for your role. It should be a very top role.
Next, choose server you’d like Rythm to join. Then sign in to your Discord account on your Browser and see the option to do it! Make sure you choose the right option, in case you have administrator permissions!
Now click on authorize. That will add Rythm to your server. Then create a voice channel for music bot.
Go back to Discord and then click + button, present on the voice channels section.
After that, name your server appropriately and make sure that you’re selecting the Voice Channel option. Now you’ve to join Rythm with your channel/ To do this, find any audio or internet, such as visit youtube for some audio. And you’re done.
How To Set Up A Discord Bot On Android/Mac
First of all, create a new application on the discord development portal.
You can do that by visiting the portal and clicking on new application.
After that, give your application a name and then click the create button.
Now select the bot tab and click on add bot.The bot has been created and you can continue with inviting it to our server.
If you have the same screen as above, the bot has been created and you can continue with inviting it to our server.
Add Bot To Server
Once the bot has been created, now you can invite it using the OAuth2 URL generator. To do that, navigate to the OAuth2 page and select bot that is in scope ta.
Then select the needed permissions to play music and read messages.
Copy your generated URL and paste onto your browser.
Then add it to your server by selecting the server of your choice and clicking the “Authorize” button.
Creating a Project
Now you can create your project. First of all, create a directory. Use these two commands to create the directory.
Then create project modules using npm init command.
Now, all you need is to open project in a text editor in order to write code. You can use VS code and open it with this command.
JS Basics For Discord
Firstly,you’ll need to install some dependencies.
At the end of the installation, you can continue writing our config.json file.
To avail your token, visit the discord developer portal and then copy it from bot section.
Now, the time has arrived to start writing JS code. First, import all dependencies.
Now create client and login – use the token for this purpose.
After that, we can create our client and login using our token.
Add a few basic listeners that console.log.
Now you can start your bot. Use node command for this purpose.
Read Messages
Now you can go online and start reading chat messages. To read messages, write one simple function.
Here we create a listener that gets the message and then save it into the message object. First, check if the message is from our own bot and ignore it if it is.
In this code, you check if the author of this message is bot. After that, the code checks if the message starts with a prefix we have defined.
Then we check which command we need to execute.
After that, we can check which command we need to execute. We do so by using some simple if statements.
Adding Audios
You’ll have to add a play command. You’ll need a song/audios and a guild. You’ll also need ytdl library, that you installed earlier. First of all, create a map with the name of the queue. In it, you’ll save all audios/songs that we type in the chat.
After that, create a function, an async function. Through this function, we check if the user is in a voice chat.
You’ll need ytdl library to check the audio info or store it into an object.
When you have saved the audio info, create a contract. Then check if your server queue is already defined – that means music is being already played.
In the code below, we check the status of serverQueue – if its empty or not. Now just create a contract if the server queue is full.
Play Audio
Now, we’ll create a function that will take two parameters. First is guild and audio we want to play. Then it’ll check if the audio is empty.
Then, we use the playstream() function to play audio of our choice.
Skip Audio
To embed skipping functionality, we create a play() function so it starts the next audio.
Stop Audio
The stop function immediately stop the audio being played.
Here You Go!
We did our best to guide you in how to create a Discord Bot, you can also drop a comment if you have any query. We really hope that the information written above proved helpful for you. Be careful while writing these chunks of code. Make sure you take care of the letter case.
If you found it useful, please share it and recommend it to others. In addition, you can also drop your precious feedback here. Did you enjoy reading it? Did it really help? If yes, then please share!
FAQs:
-What’s the best Discord bot?
Actually, there are many quality Discord bots available including GAwesome bot, Tatsumaki , Dyno Bot ,etc. It depends on your flavor which one you might prefer.
-What is a discord BOT token?
A Discord Bot Token is a short phrase (represented as a jumble of letters and number).
-How do you get a discord BOT token?
You can get a token by following the steps written in ” JS Basic For Discord” heading, written in the article above.
-How old is discord app?
It is not much old. It became popular lately.
-Is discord really safe ?
Yes, it is safe and secure to use!
-Is discord better than Skype?
For some, may be it is. For some, maybe it can still improve. Generally it depends on the purpose of one’s use.
-Is discord only for gamers?
No, besides listening to audios/songs, it can be used for various purposes including video chat, voice call, etc.
Leave a Reply