A powerful Discord bot that allows editors and edit-enjoyers alike to resync edits. What was once done manually in 30 minutes within an editor can now be done in 30 seconds automatically.
- Audio track management with 10,000+ pre-loaded tracks
- Spotify link integration (optional)
- Server tracking and analytics
- Premium user subscriptions
- User voting system
- Usage statistics and progress tracking
- Python 3.8 or higher
- PostgreSQL database
- Discord account with Developer Mode enabled
- (Optional) Spotify Developer account for Spotify features
git clone https://github.com/yourusername/resyncbot.git
cd resyncbot# Create a virtual environment (recommended)
python -m venv venv
# Or on Linux
python3 -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install required packages
pip install -r requirements.txtInstall PostgreSQL:
- macOS:
brew install postgresql && brew services start postgresql - Ubuntu/Debian:
sudo apt install postgresql postgresql-contrib - Windows: Download from postgresql.org
Install PostgreSQL:
- macOS:
brew install postgresql && brew services start postgresql - Ubuntu/Debian:
sudo apt install postgresql postgresql-contrib - Windows: Download from postgresql.org
Create a PostgreSQL user and database:
On Linux/macOS:
# Switch to postgres user and create your database
sudo -u postgres psql
# Inside psql, run these commands:
CREATE USER resyncbot_user WITH PASSWORD 'your_secure_password';
CREATE DATABASE resyncbot OWNER resyncbot_user;
GRANT ALL PRIVILEGES ON DATABASE resyncbot TO resyncbot_user;
\q
# Now import the schema (using your new user)
psql -U resyncbot_user -d resyncbot -f database/resyncbot_init.sql
# Enter the password when promptedOn Windows (PowerShell):
powershell # Open psql (will prompt for the postgres password you set during installation)
psql -U postgres
# Inside psql, run these commands:
CREATE USER resyncbot_user WITH PASSWORD 'your_secure_password';
CREATE DATABASE resyncbot OWNER resyncbot_user;
ALTER DATABASE resyncbot OWNER TO resyncbot_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO resyncbot_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO resyncbot_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO resyncbot_user;
\q
# Import the schema
psql -U resyncbot_user -d resyncbot -f database/resyncbot_init.sqlFollow Discord's official guide to create a bot application:
Discord Developer Portal - Creating a Bot Account
Quick summary:
- Go to Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" tab and click "Reset Token"
- Under "Token", click "Copy" to save your bot token
- Go to "OAuth2" > "URL Generator":
- Select scopes:
bot,applications.commands - Select necessary bot permissions (Administrator for full functionality)
- Copy the generated URL and open it to invite the bot to your server
- Select scopes:
# Copy the example environment file
# LINUX:
cp .env.example .env
# POWERSHELL
copy .env.example .envEdit .env and add your bot token as well as your database URL:
DISCORD_BOT_TOKEN=your_bot_token_from_step_4
# Database connection - UPDATE THIS with your actual password
# Format: postgresql://username:password@host:port/database
DATABASE_URL=postgresql://resyncbot_user:your_secure_password@localhost:5432/resyncbot
# Resync API
RESYNC_API_BASE=http://localhost:8000
DEBUG_MODE=true- Create
backend/cookies.txtin your project directory - Export your YouTube cookies using a browser extension like Cookie Editor
- Paste the cookies into
data/cookies.txt
For local development: Use your own YouTube account - it's safe since the file is ignored by git.
For deployment: Create a separate/burner YouTube account for security.
Note: The bot will work fine without cookies for most YouTube videos. Only add them if you encounter "Sign in to confirm your age" or similar errors.
Only needed if you want Spotify link features!
- Go to Spotify Developer Dashboard
- Click "Create an App"
- Copy your Client ID and Client Secret
- Add them to your
.env:
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secretIf you skip this step, ResyncBot will work fine - you just won't be able to use Spotify-related commands.
You need to run both the API backend and the bot:
## Terminal 1 - Start the API backend (from root)
# LINUX:
python3 backend/resync_api.py
# WINDOWS/POWERSHELL:
python backend/resync_api.py
# Terminal 2 - Start the bot
# LINUX:
python3 main.py
# WINDOWS/POWERSHELL
python main.pyNote: You may see this error initially:
API Error: ⚠️ An unexpected error occurred: Cannot connect to host resync-bot-dev.fly.dev:443 ssl:default [None]...
This is normal! It's due to Discord's caching. The bot will still work correctly - just ignore this message.
Once both services are running, go to your Discord server and try using ResyncBot commands! If everything is set up correctly, the bot should respond to commands. Keep in mind it may take a while for the commands to load, if you want to load them instantly, just reinvite the bot to your discord server via the OAuth link in the discord developer portal.
This project is organized into two main parts:
/bot- Discord bot frontend (commands, events, user interactions)/backend- Flask API server (video/audio processing, FFmpeg operations)
- Start here:
main.py- Entry point to run the Discord bot - All commands:
/bot/commands/- Each file is a Discord slash command - Processing logic:
backend/video_utils.py- All video/audio manipulation - API endpoints:
backend/resync_api.py- Main Flask server with all endpoints - Database setup:
/database/- PostgreSQL schema with 10,000 pre-loaded tracks
For a complete breakdown of every file and directory, see PROJECT_STRUCTURE.md.
- User runs a command in Discord (e.g.,
/resyncmp4) - Bot receives command and validates input
- Bot sends HTTP request to backend API
- Backend downloads media (yt-dlp), processes it (FFmpeg), and returns result
- Bot uploads the processed video back to Discord
DISCORD_BOT_TOKEN- Your Discord bot token (required)DATABASE_URL- PostgreSQL connection string (required)RESYNC_API_BASE- API backend URL (default: http://localhost:8000)DEBUG_MODE- Enable verbose logging (default: true)SPOTIFY_CLIENT_ID- Spotify API client ID (optional)SPOTIFY_CLIENT_SECRET- Spotify API client secret (optional)LOG_CHANNEL_ID- Discord channel ID for bot logs (optional)
See database/README.md for detailed database documentation.
"Cannot connect to host" error on startup:
- This is expected! Discord's caching causes this. The bot works normally - ignore it.
Bot not responding to commands:
- Make sure both
main.pyandresync_api.pyare running - Check that Message Content Intent is enabled in Discord Developer Portal
- Verify your bot token is correct in
.env
Database connection errors:
- Ensure PostgreSQL is running
- Check your
DATABASE_URLis correct - Verify the database was initialized with
resyncbot_init.sql
Spotify features not working:
- Spotify integration is optional - the bot works without it
- If you want Spotify features, verify your credentials are correct
- Check the Spotify Developer Dashboard for API status
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
If you encounter issues:
- Check the Troubleshooting section above
- Open an issue on GitHub with details about your problem
- Include error messages and your environment (OS, Python version, etc.)
MIT License - Feel free to use this project for your own Discord server!
- Built with discord.py
- Spotify integration via Spotipy
- Database: PostgreSQL
