Are you exploring to know how to make a discord bot? Discord is a chat application that supports millions of users across the globe to message and voice chat online in communities called guilds or servers. Discord also gives an extensive API that developers can use to build powerful Discord bots. Bots can perform different actions such as sending messages to servers, DM-ing users, moderating servers, and playing audio in voice chats.
This allows developers to craft powerful bots that combine advanced, complex features like moderation tools or even games. For example, the use of bot Dyno serves millions of guilds and contains useful features such as spam protection, a music player, and other utility functions. Discovering how to create Discord bots allows you to implement many possibilities, which thousands of people could interact with every day.
How to Make a Discord Bot – Developer Portal Guide
Before you can dive into any Python code to handle events and create exciting automation, you need first to make a few Discord components:
- An account
- An application
- A bot
- A guild
You’ll see more about each piece in the following sections. Once you’ve built all of these components, you’ll tie them together by registering your bot with your guild. You can obtain started by heading to Discord’s Developer Portal.
Creating a Discord Account
The first thing you’ll see is a landing page where you’ll need to either log in if you have an existing account or create a new account. If you need to create a new account, then press the Register button below Login and enter your account information.
Necessary: You’ll need to verify your email before you’re able to move on. Once you’re completed, you’ll be redirected to the Developer Portal home page, where you’ll create your application.
Creating an Application
An application allows you to communicate with Discord’s APIs by providing authentication tokens, designating permissions, and so on. To create a new application, select New Application. Next, you’ll be prompted to name your application. Select a name and click Create.
You made a Discord application. On the resulting screen, you can see details about your application. Keep in mind that any program that combines with Discord APIs requires a Discord application, not just bots. Bot-related APIs are only a subset of Discord’s entire interface. However, since this tutorial is about how to make a Discord bot, navigate to the Boot tab on the left-hand navigation list.
Creating a Bot
As you learned in the previous sections, a bot user is one that listens to and automatically reacts to specific events and commands on Discord. For your code to be manifested on Discord, you’ll need to create a bot user. To do so, select Add Bot. Once you verify that you want to add the bot to your application, you’ll see the new bot user in the portal.
Notice that, by default, your bot user will receive the name of your application. Alternatively, update the username to something more bot-like, such as RealPythonTutorialBot, and Save Changes. Now, the bot’s all set and eager to go, but to where? A bot user is not helpful if it’s not interacting with other users. Next, you’ll build a guild so that your bot can interact with other users.
Creating a Guild
A guild (or a server, as it is often called in Discord’s user interface) is a special group of channels where users congregate to chat. Note: While guild and server are interchangeable, this article will use the term guild primarily because of the APIs stick to the same term. The name server will only be used when referring to a guild in the graphical UI.
For instance, say you want to create a space where users can come together and talk about your latest game. You’d start by creating a guild. Then, in your guild, you could have many channels, such as:
- General Discussion: A medium for users to talk about whatever they want
- Spoilers, Beware: A medium for users who have finished your game to talk about all the end game reveals
- Announcements: A medium for you to announce game updates and for users to discuss them
Once you’ve built your guild, you’d invite other users to populate it. So, to form a guild, head to your Discord home page. From this home page, you can see and add friends, direct messages, and guilds. From here, choose the + icon on the left-hand side of the web page to Add a Server.
This will present two options, Build a server and Join a Server. In this case, choose to create a server and enter a name for your guild. Once you’ve completed creating your guild, you’ll be able to see the users on the right-hand side and the channels on the left. The last step on Discord is to register your bot with your new guild.
Adding a Bot to a Guild
A bot can’t accept invites as a regular user can. Alternatively, you’ll add your bot using the OAuth2 protocol.
Technical information: OAuth2 is a protocol for dealing with authorization, where a service can grant a client application limited access based on the application’s credentials and allowed scopes. To do so, head back to the Developer Portal and choose the OAuth2 page from the left-hand navigation:
From this window, you’ll notice the OAuth2 URL Generator. This tool makes an authorization URL that hits Discord’s OAuth2 API and authorizes API access using your application’s credentials.
In this example, you’ll want to grant your application’s bot user access to Discord APIs using your application’s OAuth2 credentials. To do this, scroll down and choose bot from the SCOPES options and Administrator from BOT PERMISSIONS:
Now, Discord has made your application’s authorization URL with the selected scope and permissions. Choose Copy beside the URL that was generated for you, paste it into your browser, and select your guild from the dropdown options. Click Authorize, and you’re done!
If you go back to your guild, then you’ll see that the bot has been attached. In summary, you’ve created:
- An application that your bot will use to confirm with Discord’s APIs.
- A bot user that you’ll use to socialize with other users and events in your guild.
- A guild in which your user account and your bot user will be determined.
- A Discord account with which you built everything else and that you’ll use to interact with your bot.
Now, you know how to create a Discord bot using the Developer Portal. Next comes the fun stuff: achieving your bot in Python!
- How Does Apple TV Work? Installation & Working Process - April 11, 2021
- How to Transfer Contacts from Android to iPhone? - April 10, 2021
- Windows 10 Search Not Working? Try These Easy Fixes - April 10, 2021