A Discord bot that notifies when someone joins a voice channel
Project description
๐ Discord Voice Notifier Bot
A lightweight, self-hostable Discord bot that sends a notification to a designated text channel whenever a member joins a voice channel in your server. Built with Python and discord.py, it's easy to configure, secure by design, and built to run permanently in the background on a Linux machine.
๐ Table of Contents
- Features
- Prerequisites
- Creating the Discord Bot
- Installation
- Configuration
- Running the Bot
- Self-Hosting on Linux with systemd
- Updating the Bot
- Project Structure
- Troubleshooting
- Security
- Contributing
- License
โจ Features
- ๐ฃ Sends a notification message to a text channel whenever a member joins a voice channel
- ๐ Secure credential handling via environment variables โ no tokens ever in source code
- ๐ง Designed to be self-hosted on a Linux machine using
systemd - โป๏ธ Automatically restarts if the bot crashes
- ๐ Starts automatically on server reboot
- ๐งฉ Easy to extend with additional events or commands
๐งฐ Prerequisites
Before you begin, make sure you have the following:
- A Discord account
- Access to the Discord Developer Portal
- Admin permissions on the Discord server you want the bot in
- A Linux machine to host the bot (a VPS, home server, or Raspberry Pi all work)
- Python 3.8 or higher installed on that machine
gitinstalled on that machine
๐ค Creating the Discord Bot
You need to create a bot user in the Discord Developer Portal before running any code.
Step 1 โ Create an Application
- Go to discord.com/developers/applications and log in
- Click "New Application" in the top right corner
- Give it a name (e.g.
VoiceNotifier) and click Create
Step 2 โ Create the Bot User
- On the left sidebar, click "Bot"
- Click "Add Bot" โ confirm with "Yes, do it!"
- Click "Reset Token" and copy the token that appears โ save this somewhere safe, you won't see it again
โ ๏ธ Never share your bot token with anyone or commit it to GitHub. If it is ever exposed, immediately click "Reset Token" to invalidate the old one.
Step 3 โ Enable Privileged Gateway Intents
Still on the Bot page, scroll down to "Privileged Gateway Intents" and enable:
- โ Server Members Intent โ required to receive member information
- โ Message Content Intent โ required for the bot to interact with messages
- โ Presence Intent โ optional, needed only if you want to filter by online status
Click Save Changes.
Step 4 โ Get Your Notification Channel ID
- Open Discord and go to User Settings โ Advanced
- Toggle on Developer Mode
- Right-click the text channel where you want notifications to be posted
- Click "Copy Channel ID" and save it alongside your token
Step 5 โ Invite the Bot to Your Server
- In the Developer Portal, navigate to OAuth2 โ URL Generator on the left sidebar
- Under Scopes, tick:
bot - Under Bot Permissions, tick:
View ChannelsSend MessagesConnect
- Copy the generated URL at the bottom of the page
- Paste it into your browser, select your server, and click Authorise
๐ ๏ธ Installation
There are two ways to install the bot โ cloning the repo directly, or installing it as a package via pip from PyPI. Both approaches are fully supported.
Option A: Clone from GitHub
1. Clone the Repository
git clone https://github.com/yourusername/discord-voice-notifier.git
cd discord-voice-notifier
2. Create a Virtual Environment
A virtual environment keeps the bot's dependencies isolated from the rest of your system:
python3 -m venv venv
source venv/bin/activate
3. Install Dependencies
pip install -r requirements.txt
Option B: Install via pip from PyPI
If the package has been published to PyPI, you can install it directly without cloning the repo at all.
1. Create a directory to hold your configuration
mkdir ~/discord-bot
cd ~/discord-bot
2. Create a virtual environment
python3 -m venv venv
3. Install the package into the venv
venv/bin/pip install discord-voice-notifier
4. Create your .env file
nano .env
Add your credentials:
DISCORD_TOKEN=your_bot_token_here
NOTIFICATION_CHANNEL_ID=your_channel_id_here
Save and close (Ctrl+X โ Y โ Enter).
5. Run the bot to test it
venv/bin/discord-voice-notifier
You should see:
โ
Bot is online โ logged in as VoiceNotifier#1234
๐ข Sending notifications to channel ID: 123456789
Press Ctrl+C to stop โ then follow the Running from a pip Install section below to run it permanently as a service.
โ๏ธ Configuration
The bot uses a .env file to store sensitive credentials. This file is listed in .gitignore and will never be committed to GitHub.
1. Copy the example environment file
cp .env.example .env
2. Fill in your values
Open .env in a text editor:
nano .env
Replace the placeholder values with your own:
DISCORD_TOKEN=your_bot_token_here
NOTIFICATION_CHANNEL_ID=your_channel_id_here
| Variable | Description | Where to get it |
|---|---|---|
DISCORD_TOKEN |
Your bot's secret token | Discord Developer Portal โ Bot โ Reset Token |
NOTIFICATION_CHANNEL_ID |
The ID of the text channel to post notifications in | Discord โ Right-click channel โ Copy Channel ID |
Save and close the file (Ctrl+X โ Y โ Enter if using nano).
โถ๏ธ Running the Bot
Once configured, you can run the bot directly to test it:
python3 bot.py
You should see output like:
โ
Bot is online โ logged in as VoiceNotifier#1234
๐ข Sending notifications to channel ID: 123456789
Now try joining a voice channel in your server โ you should see a notification appear in your designated text channel.
Press Ctrl+C to stop the bot. To run it permanently in the background, follow the section below.
๐ง Self-Hosting on Linux with systemd
systemd is a Linux service manager that will keep your bot running in the background, restart it if it crashes, and start it automatically whenever your server reboots.
The service file differs slightly depending on whether you installed via pip or cloned the repo โ follow the relevant section below.
Running from a Cloned Repo
Step 1 โ Create the Service File
sudo nano /etc/systemd/system/discord-bot.service
Paste the following, replacing your_linux_username with your actual username (whoami if unsure):
[Unit]
Description=Discord Voice Notification Bot
After=network.target
[Service]
Type=simple
User=your_linux_username
WorkingDirectory=/home/your_linux_username/discord-voice-notifier
EnvironmentFile=/home/your_linux_username/discord-voice-notifier/.env
ExecStart=/home/your_linux_username/discord-voice-notifier/venv/bin/python3 bot.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Step 2 โ Enable and Start the Service
# Reload systemd so it picks up the new service file
sudo systemctl daemon-reload
# Enable the service to start automatically on boot
sudo systemctl enable discord-bot
# Start the service now
sudo systemctl start discord-bot
Step 3 โ Verify It's Running
sudo systemctl status discord-bot
You should see Active: active (running) in green.
Running from a pip Install
Step 1 โ Create the Service File
sudo nano /etc/systemd/system/discord-bot.service
Paste the following, replacing your_linux_username with your actual username:
[Unit]
Description=Discord Voice Notification Bot
After=network.target
[Service]
Type=simple
User=your_linux_username
WorkingDirectory=/home/your_linux_username/discord-bot
EnvironmentFile=/home/your_linux_username/discord-bot/.env
ExecStart=/home/your_linux_username/discord-bot/venv/bin/discord-voice-notifier
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
The key differences from the cloned repo version are:
WorkingDirectorypoints to the config folder rather than a cloned repoEnvironmentFilepoints to the.envfile in that config folderExecStartpoints to the installed CLI command inside the venv rather than a Python script
โน๏ธ Not sure where the command was installed? Run
find ~/discord-bot/venv/bin -name "discord-voice-notifier"to confirm the exact path.
Step 2 โ Enable and Start the Service
# Reload systemd so it picks up the new service file
sudo systemctl daemon-reload
# Enable the service to start automatically on boot
sudo systemctl enable discord-bot
# Start the service now
sudo systemctl start discord-bot
Step 3 โ Verify It's Running
sudo systemctl status discord-bot
You should see Active: active (running) in green.
Useful Service Commands
| Command | Description |
|---|---|
sudo systemctl status discord-bot |
Check if the bot is running |
sudo systemctl start discord-bot |
Start the bot |
sudo systemctl stop discord-bot |
Stop the bot |
sudo systemctl restart discord-bot |
Restart the bot (use after updates) |
sudo journalctl -u discord-bot -f |
View live logs |
sudo journalctl -u discord-bot --since today |
View today's logs |
๐ Updating the Bot
If installed from a cloned repo
cd discord-voice-notifier
git pull
sudo systemctl restart discord-bot
If installed via pip
cd ~/discord-bot
venv/bin/pip install --upgrade discord-voice-notifier
sudo systemctl restart discord-bot
Check the logs to confirm everything started correctly:
sudo journalctl -u discord-bot -f
๐ Project Structure
discord-voice-notifier/
โโโ bot.py # Main bot logic
โโโ .env # Your secret credentials (never committed)
โโโ .env.example # Safe template for others to copy
โโโ .gitignore # Ensures .env is never tracked by git
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
๐ง Troubleshooting
Bot is online but no notifications are appearing
- Double-check that
NOTIFICATION_CHANNEL_IDin your.envfile is correct - Make sure the bot has
Send MessagesandView Channelspermissions in that channel - Confirm the bot was invited to the server using the correct OAuth2 URL
discord.errors.PrivilegedIntentsRequired error
- Go to the Discord Developer Portal โ Your App โ Bot
- Make sure Server Members Intent and Message Content Intent are both enabled
- Click Save Changes and restart the bot
ValueError: DISCORD_TOKEN is missing error
- Make sure your
.envfile exists and containsDISCORD_TOKEN=your_token_here - Make sure you ran
cp .env.example .envand filled in the values
Bot goes offline after closing the SSH session
- You need to set up the
systemdservice as described in the Self-Hosting section - Without it, the bot only runs while your terminal is open
command not found: discord-voice-notifier after pip install
- Make sure you are referencing the venv binary directly:
~/discord-bot/venv/bin/discord-voice-notifier - Or confirm the install path with:
find ~/discord-bot/venv/bin -name "discord-voice-notifier"
ModuleNotFoundError: No module named 'discord'
- Make sure your virtual environment is active:
source venv/bin/activate - Then install dependencies:
pip install -r requirements.txt
Bot token was accidentally committed to GitHub
- Immediately go to the Developer Portal โ Bot โ Reset Token
- Update your
.envfile with the new token - Remove the token from your git history (see GitHub's guide on removing sensitive data)
๐ Security
This project is designed with security in mind:
- No credentials in source code โ all tokens and IDs live in
.env, which is excluded from version control via.gitignore .env.exampleis provided so others know what variables are needed without exposing any real values- Anyone cloning this repo simply copies
.env.exampleto.envand fills in their own credentials
Best practices to follow:
- Never share your bot token publicly
- Regenerate your token immediately if you suspect it has been exposed
- Restrict bot permissions to only what it needs (
Send Messages,View Channels,Connect) - Keep your Linux server and Python packages up to date
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file discord_voice_notifier-0.0.0.tar.gz.
File metadata
- Download URL: discord_voice_notifier-0.0.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8e9ad32d76f14534a842958314671e94493e60668ab1376526a2189c9d312e9
|
|
| MD5 |
38be22da75aa0b863f46a966d7ce903b
|
|
| BLAKE2b-256 |
4c2ac70c954263f37d0db28f57949ec8177e341562e077a3dbb91c95a2257183
|
File details
Details for the file discord_voice_notifier-0.0.0-py3-none-any.whl.
File metadata
- Download URL: discord_voice_notifier-0.0.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1fc18c7887c49dfbcfd9090297da8c08e51f7c37a6f7be86e0e79be213b91e0
|
|
| MD5 |
b7257c33f1c921ec0a52940b7902f542
|
|
| BLAKE2b-256 |
d11bde3c0c50293f8a90d85bae7ae36cd9e01b48da6c047776b26a3f7f580316
|