Required Variables
Your Discord bot token from the Discord Developer Portal
Never share your bot token publicly or commit it to version control
Your Groq API key for AI-powered responses using LLaMA 3.3 70BGet your API key from Groq Console
Setup
Create a.env file in the root directory of your bot:
.env
Loading Environment Variables
ChimBot usespython-dotenv to load environment variables automatically at startup:
main.py
main.py starts running (line 11).
Getting Your Discord Token
Go to Discord Developer Portal
Visit discord.com/developers/applications and create a new application
Getting Your Groq API Key
Create Groq Account
Sign up at console.groq.com
Validation
To verify your environment variables are loaded correctly:Security Best Practices
Use .env files
Store all sensitive credentials in
.env files, never in source codeAdd to .gitignore
Ensure
.env is in your .gitignore file to prevent commitsRotate keys regularly
Periodically regenerate your API keys and tokens
Limit permissions
Only grant the minimum required Discord permissions
Troubleshooting
Error: TOKEN not found
Error: TOKEN not found
- Verify
.envfile exists in the same directory asmain.py - Check that
python-dotenvis installed:pip install python-dotenv - Ensure there are no spaces around the
=in your.envfile - Verify the variable name is exactly
TOKEN(case-sensitive)
Error: GROQ_API_KEY not found
Error: GROQ_API_KEY not found
- Confirm your Groq API key is valid and active
- Check the variable name matches exactly:
GROQ_API_KEY - Verify you’ve copied the entire key without truncation
Bot doesn't respond
Bot doesn't respond
- Verify both environment variables are set correctly
- Check the bot has proper Discord permissions
- Ensure privileged intents are enabled in Discord Developer Portal
- Review the console for error messages
Next Steps
Customize Bot Behavior
Configure personality, spam detection, and more
Set Permissions
Learn about required Discord permissions