Prerequisites
Before you begin, make sure you have:- Java SE 8 or higher installed
- A Discord account
- Basic knowledge of Java programming
Creating Your Bot Application
Access the Discord Developer Portal
Navigate to the Discord Application Dashboard and log in with your Discord account.
Create a New Application
Click the New Application button in the top right corner. Enter a name for your application and click Create.
Navigate to the Bot Section
In the left sidebar, click on Bot. Then click Add Bot to create a bot user for your application.
Get Your Bot Token
Click Reset Token to generate a new bot token. Copy this token immediately and store it securely - you won’t be able to see it again.
Configure Privileged Gateway Intents
Scroll down to the Privileged Gateway Intents section. Enable any intents your bot needs:
- Presence Intent - For member status/activities
- Server Members Intent - For member join/leave events
- Message Content Intent - For reading message content
You must explicitly enable privileged intents both in the Developer Portal AND in your code.
Setting Up Your Project
Adding JDA to Your Project
Storing Your Bot Token
Never hardcode your token directly in your source code. Here are recommended approaches:Option 1: Environment Variable (Recommended)
Option 2: Configuration File
Store the token in a file that’s added to.gitignore:
Option 3: System Property
Choosing a Builder Preset
JDA provides three factory methods for creating your bot, each with different cache configurations:createLight()
Minimal cache profile for low memory usage:- Disables all user cache and cache flags
- Lowest memory footprint
- Best for bots that don’t need member information
createDefault()
Recommended default settings:- Caches users who are active in voice channels
- Enables most cache flags
- Good balance between features and memory
create()
Full cache profile:- Enables member chunking
- Caches all users
- Highest memory usage but full functionality
Understanding Gateway Intents
Intents control which events your bot receives. This improves performance by only processing events you need.Your First Bot
Here’s a complete example that logs in and waits until ready:Next Steps
Now that you have a bot running, you can:- Build a message logging bot
- Implement slash commands
- Handle interactions
- Learn about error handling patterns
Common Issues
”Invalid Token” Error
Make sure:- You copied the entire token without extra spaces
- The token is from the Bot section, not the application ID
- You haven’t regenerated the token since copying it
Missing Events
If events aren’t firing:- Verify the required intent is enabled in both code AND the Developer Portal
- Check that your event listener is properly registered
- Ensure the event you’re listening for matches the enabled intents
Bot Not Responding
Remember to call.queue() on all RestActions: