Setup & Configuration¶
This guide will help you set up and run Sonata bot on your own Discord server.
Prerequisites¶
Before you begin, make sure you have:
- Python 3.10+ installed on your system
- A Discord Bot Token from the Discord Developer Portal
- A Last.fm API key from Last.fm API
- A Genius API token from Genius API
Installation¶
1. Clone the Repository¶
2. Install Dependencies¶
You can install dependencies using pip:
Or use the justfile:
3. Configure Environment Variables¶
Create a .env file in the root directory with the following variables:
# Discord Bot Token (Required)
DISCORD_TOKEN=your_discord_bot_token_here
# Last.fm API Credentials (Required)
LASTFM_API_KEY=your_lastfm_api_key_here
LASTFM_API_SECRET=your_lastfm_api_secret_here
# Genius API Token (Required for lyrics and samples commands)
GENIUS_API_TOKEN=your_genius_token_here
# Database Configuration (Optional)
DATABASE_PATH=./sonata.db
4. Set Up the Database¶
The bot uses SQLite for storing ratings and user information. The database will be created automatically on first run, but you can initialize it manually:
Or:
Running the Bot¶
Once everything is configured, you can start the bot:
Or:
The bot should now be online and ready to use!
Discord Bot Setup¶
Creating a Bot Application¶
- Go to the Discord Developer Portal
- Click "New Application" and give it a name
- Navigate to the "Bot" section in the left sidebar
- Click "Add Bot"
- Under the "Token" section, click "Copy" to get your bot token
- Paste this token into your
.envfile asDISCORD_TOKEN
Bot Permissions¶
The bot requires the following permissions:
- Read Messages/View Channels
- Send Messages
- Embed Links
- Attach Files
- Read Message History
- Use External Emojis
- Add Reactions
Permission Integer: 397284600896
Inviting the Bot to Your Server¶
- In the Developer Portal, go to the "OAuth2" > "URL Generator" section
- Select the "bot" scope
- Select the permissions listed above
- Copy the generated URL and open it in your browser
- Select the server you want to add the bot to and click "Authorize"
API Keys¶
Getting a Last.fm API Key¶
- Visit Last.fm API Account Creation
- Fill out the form with your application details
- You'll receive an API Key and Shared Secret
- Add both to your
.envfile
Getting a Genius API Token¶
- Visit Genius API Clients
- Click "New API Client"
- Fill out the form with your application details
- Once created, click "Generate Access Token"
- Copy the token and add it to your
.envfile
Troubleshooting¶
Bot doesn't respond to commands¶
- Verify the bot has proper permissions in your server
- Check that the
DISCORD_TOKENin your.envfile is correct - Make sure the bot is online (check the console for any error messages)
- Try syncing slash commands:
!sync guildor!sync global
Import ratings fails¶
- Ensure your CSV file is exported correctly from RateYourMusic
- Check that the file format matches RYM's export format
- Wait for the import to complete - large libraries can take several minutes
Last.fm integration not working¶
- Verify your
LASTFM_API_KEYandLASTFM_API_SECRETare correct - Make sure you've set your Last.fm username with
!setlastfm - Check that your Last.fm profile is public
Lyrics/Samples not found¶
- Ensure your
GENIUS_API_TOKENis valid - Not all tracks have lyrics or sample information available
- Try using the full artist and track name
Development¶
For development work, you can use the development setup:
This will install the package in editable mode with development dependencies.
Running Tests¶
Code Quality¶
Check code quality:
Auto-fix linting issues:
Format code:
Documentation¶
To build and serve the documentation locally:
The documentation will be available at http://127.0.0.1:8000/.
Support¶
If you encounter any issues or have questions:
- Check the GitHub Issues page
- Review the documentation thoroughly
- Make sure all API keys are configured correctly
- Check the console output for detailed error messages