How to Create a Discord Bot and Add It to Your Server
In this article
You can automate tasks, moderate content, and enhance community engagement by creating a custom Discord bot. This process involves registering the bot on the Discord Developer Portal, generating an authentication token, and using an OAuth2 link to invite it to your specific server. No coding knowledge is required for basic setup, though you will need a Discord account and a server you own or manage.
What You'll Need
- A valid Discord account with email verification enabled.
- Access to a Discord server where you have Administrator permissions.
- A web browser to access the Discord Developer Portal.
- (Optional) A code editor if you plan to write custom scripts later.
Step-by-Step
- Create a New Application: Navigate to the Discord Developer Portal in your browser. Click the "New Application" button in the top right corner. Enter a name for your bot (this will be the default display name) and click "Create."
- Add the Bot Instance: In the left-hand sidebar of your new application page, click on "Bot." Click the "Add Bot" button to confirm. This step converts your general application into a bot account capable of joining servers.
- Generate the Token: Under the "Token" section on the Bot page, click "Copy." This string of characters is your secret key. Keep this private; anyone with this token can control your bot. If you lose it, you must regenerate it immediately.
- Configure Privileged Gateway Intents: Scroll down to the "Privileged Gateway Intents" section. Toggle on "Message Content Intent" if your bot needs to read message text. Also enable "Server Members Intent" if your bot needs to see user lists. These settings are crucial for modern bot functionality.
- Invite the Bot to Your Server: Go to the "OAuth2 > URL Generator" tab in the left sidebar. Under "Scopes," select "bot." Then, under "Bot Permissions," check the boxes for permissions your bot needs (e.g., "Send Messages," "Manage Roles," "Read Message History"). Copy the generated URL at the bottom.
- Authorize the Invite: Paste the copied URL into a new browser tab. Select the server you want to add the bot to from the dropdown menu. Click "Authorize." Complete the CAPTCHA verification if prompted. The bot will now appear offline in your server's member list.
- Test the Bot: Switch to your Discord client. If you enabled the correct intents and permissions, type a command or message that triggers your bot. Note that without backend code running, the bot will not respond to commands yet; it is simply present in the server.
Common Mistakes
Many users fail because they skip the "Privileged Gateway Intents" configuration. Discord requires explicit permission for bots to read message content or member lists due to privacy changes. If these are off, your bot may appear online but receive no data.
Another frequent error is copying the Client ID instead of the Bot Token. The Token is found under the "Bot" tab, while the Client ID is in the "General Information" tab. Using the wrong string will prevent your bot from authenticating.
Users also often forget to grant necessary permissions during the OAuth2 invite process. If you do not give the bot "Send Messages" or "Read Message History" permissions, it will join the server but be unable to interact with chats.
Tips
Always use environment variables to store your bot token. Never hardcode the token directly into your script files, especially if you plan to share your code publicly. This prevents accidental leaks.
Start with minimal permissions. Only request the permissions your bot actually needs. This follows the principle of least privilege and reduces security risks. You can always adjust permissions later via the OAuth2 generator.
Use a dedicated testing server before adding your bot to a large public community. This allows you to debug issues without disrupting active users. Create a small server just for development purposes.
Troubleshooting
If the bot does not appear in your server after inviting, verify that you selected the correct server in the OAuth2 dropdown menu. Sometimes users accidentally invite the bot to a different server they own.
If the bot appears offline, ensure that the privileged gateway intents are enabled in the Developer Portal. Additionally, check that your hosting environment (if running locally) is connected to the internet and that the bot token is correctly pasted into your code.
If the bot joins but cannot read messages, double-check the "Message Content Intent" toggle. Even with the "Read Message History" permission granted, the intent must be turned on for the bot to receive text data.
If you encounter authorization errors, try regenerating the bot token and updating your code. Ensure that the bot has not been banned or restricted by server moderators. Check the server's audit log for any recent changes to bot permissions.
Frequently Asked Questions
Can I create a Discord bot without coding?
You can create the bot account and invite it to your server without coding. However, to make it perform actions like responding to commands, you must write code or use a third-party platform that provides pre-built bots.
Is my bot token safe to share?
No. Your bot token is equivalent to a password. Sharing it allows others to take full control of your bot. Never post it in public forums, GitHub repositories, or chat logs.
Why does my bot show as offline?
This usually means the bot's code is not running, or the connection was dropped. Ensure your hosting script is active and that the token is correct. It may also indicate network issues on your end.
Do I need to pay for a Discord bot?
No. Creating a bot and hosting it on your own computer or a free tier cloud service is completely free. Discord does not charge fees for bot accounts.
How do I remove a bot from my server?
Go to your server settings, find the "Integrations" or "Bots" section, select the bot, and click "Remove." Alternatively, you can revoke its access via the OAuth2 link or kick it like a regular member.