A Python bot that fetches recently added media from a Plex server and sends updates to a Discord channel. This bot is modular, easy to configure, and designed for extensibility. Ideal for notifying users about new media added to your Plex library.
- Fetches recently added media from a Plex server.
- Sends media details and thumbnails to a Discord channel.
- Avoids duplicates by caching the last runtime.
- Modular design for easy customization and extension.
- Works with environment variables for secure configuration.
-
Clone the Repository:
git clone https://github.com/your-username/plex-discord-bot.git cd plex-discord-bot
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
- Create a
.env
file in the project root:PLEX_SERVER_IP=localhost PLEX_TOKEN=your-plex-token DISCORD_TOKEN=your-discord-token CHANNEL_ID=1234567890 LAST_RUNTIME_FILE=last_runtime.txt CHECK_INTERVAL=60
- Create a
-
Run the Bot:
python main.py
-
Plex Server:
- Ensure your Plex server is running and accessible.
- Obtain your Plex Token (Guide).
-
Discord Bot:
- Create a Discord bot at the Discord Developer Portal.
- Obtain your bot token and invite the bot to your server.
-
Environment Variables:
- Store sensitive data in the
.env
file to keep it secure.
- Store sensitive data in the
Variable | Description |
---|---|
PLEX_SERVER_IP |
IP or domain of your Plex server. |
PLEX_TOKEN |
Plex authentication token. |
DISCORD_TOKEN |
Discord bot token. |
CHANNEL_ID |
Discord channel ID for sending updates. |
LAST_RUNTIME_FILE |
Path to cache file for the last runtime. |
CHECK_INTERVAL |
Time interval (in seconds) between checks. |
- The bot uses
last_runtime.txt
to store the last runtime. - If the file doesn't exist, it will be created automatically.
- To reset, delete the file and restart the bot.
- Start the bot:
python main.py
- The bot will:
- Query your Plex server every
CHECK_INTERVAL
seconds. - Send an embed message for each new media item added since the last check.
- Query your Plex server every
plex-discord-bot/
├── main.py # Entry point for the bot.
├── discord_bot.py # Discord bot logic.
├── plex.py # Plex API interaction.
├── runtime_cache.py # Cache management.
├── config.py # Configuration setup.
├── requirements.txt # Python dependencies.
└── README.md # Documentation.
-
plex.py
- Handles interaction with the Plex API.
- Fetches recently added media and parses XML responses.
-
runtime_cache.py
- Manages the last runtime cache file.
-
discord_bot.py
- Contains all Discord-related logic.
- Sends embed messages to the specified channel.
-
config.py
- Loads environment variables for configuration.
-
main.py
- The entry point for starting the bot.
- Initializes and runs the bot.
-
Fork the Repository:
- Click the "Fork" button at the top of this page.
-
Create a New Branch:
git checkout -b feature/your-feature-name
-
Commit Changes:
git commit -m "Add your message here"
-
Push Changes:
git push origin feature/your-feature-name
-
Submit a Pull Request:
- Go to your forked repository and click "New Pull Request".
This project is licensed under the MIT License. See the LICENSE
file for details.
Happy Coding! 🎉