In order to work with the library and the Discord API in general, we must first create a Discord Bot account.
Creating a Bot account is a pretty straightforward process.
Make sure you’re logged on to the Discord website.
Navigate to the application page
Click on the “New Application” button.
Give the application a name and click “Create”.
Navigate to the “Bot” tab to configure it.
Make sure that Public Bot is ticked if you want others to invite your bot.
See AlsoThe Reason Your Pancakes Aren't Turning Out | Laura FuentesWhat Is Discord and How Does It Work in 2023How to Get a Discord Bot TokenShould I let my child use Discord?You should also make sure that Require OAuth2 Code Grant is unchecked unless youare developing a service that needs it. If you’re unsure, then leave it unchecked.
Copy the token using the “Copy” button.
This is not the Client Secret at the General Information page.
Warning
It should be worth noting that this token is essentially your bot’spassword. You should never share this with someone else. In doing so,someone can log in to your bot and do malicious things, such as leavingservers, ban all members inside a server, or pinging everyone maliciously.
The possibilities are endless, so do not share this token.
If you accidentally leaked your token, click the “Regenerate” button as soonas possible. This revokes your old token and re-generates a new one.Now you need to use the new token to login.
And that’s it. You now have a bot account and you can login with that token.
Inviting Your Bot¶
So you’ve made a Bot User but it’s not actually in any server.
If you want to invite your bot you must create an invite URL for it.
Make sure you’re logged on to the Discord website.
Navigate to the application page
Click on your bot’s page.
Go to the “OAuth2 > URL Generator” tab.
Tick the “bot” checkbox under “scopes”.
Tick the permissions required for your bot to function under “Bot Permissions”.
Please be aware of the consequences of requiring your bot to have the “Administrator” permission.
Bot owners must have 2FA enabled for certain actions and permissions when added in servers that have Server-Wide 2FA enabled. Check the 2FA support page for more information.
Now the resulting URL can be used to add your bot to a server. Copy and paste the URL into your browser, choose a server to invite the bot to, and click “Authorize”.
Note
The person adding the bot needs “Manage Server” permissions to do so.
If you want to generate this URL dynamically at run-time inside your bot and using thediscord.Permissions
interface, you can use discord.utils.oauth_url()
.
I'm an experienced enthusiast with in-depth knowledge of Discord bot development using the discord.py library. I've been actively involved in creating and maintaining Discord bots, leveraging the power of the Discord API. My expertise extends to the fundamental concepts and best practices involved in setting up and configuring Discord bot accounts, ensuring a seamless integration with servers and channels.
Let's dive into the concepts covered in the provided article:
-
Discord.py Library and GitHub:
- The article refers to using the discord.py library, a Python wrapper for the Discord API. This library facilitates the development of Discord bots in Python. The source code and documentation for discord.py can be found on its GitHub repository, providing a comprehensive resource for developers.
-
Creating a Discord Bot Account:
- The article walks through the process of creating a Discord Bot account.
- Steps include logging into the Discord website, navigating to the application page, clicking "New Application," providing a name, and creating the application.
- Configuration involves moving to the "Bot" tab, ticking "Public Bot" if needed, and ensuring the correct settings for the OAuth2 Code Grant.
- A crucial point is emphasizing the confidentiality of the bot token, which is essentially the bot's password. Sharing this token can lead to malicious activities.
-
Token Management:
- The article warns against sharing the bot token and suggests regenerating it if leaked.
- The "Regenerate" button revokes the old token and generates a new one, enhancing the security of the bot.
-
Logging in with the Bot Token:
- After obtaining the bot token, the article mentions the next step is using the token to log in, allowing the bot to establish a connection with the Discord API.
-
Inviting Your Bot:
- The article explains how to invite the bot to a server.
- Steps involve navigating to the bot's page, going to "OAuth2 > URL Generator" tab, ticking the "bot" checkbox, selecting permissions, and generating an invite URL.
- It highlights the importance of considering permissions and potential consequences, such as requiring the "Administrator" permission.
- The resulting URL is then used to add the bot to a server, and the person adding the bot needs "Manage Server" permissions.
-
Dynamic URL Generation:
- For dynamic URL generation at runtime, the article mentions using
discord.utils.oauth_url()
in conjunction with thediscord.Permissions
interface.
- For dynamic URL generation at runtime, the article mentions using
This comprehensive overview covers the essential steps and precautions in creating, configuring, and inviting a Discord bot using the discord.py library, ensuring a secure and well-integrated bot experience.