Discord LNbits Bot
This bot allows users to purchase a Discord role using Bitcoin Lightning payments through LNbits. Users request an invoice via a slash command, and the bot automatically assigns the role once payment is confirmed.
Features
✅ Users request an invoice using /support
(configurable).
✅ The bot generates a Lightning invoice via LNbits.
✅ Once paid, the bot assigns a Discord role.
✅ Configurable check intervals & max attempts to verify payments.
Requirements
- Ubuntu 24.04
- Python 3.10+
- A Discord Bot Token (from the Developer Portal)
- LNbits Wallet Invoice Key
- A running LNbits instance (e.g., Sats.Love)
1️⃣ Setting Up Your Bot
Generate a Proper Bot Invite Link
- Go to: Discord Developer Portal
- Click New Application
- Go to OAuth2 > URL Generator
- Check these Scopes:
- ✅ bot
- ✅ applications.commands (for slash commands)
- Under Bot Permissions, check:
- ✅ Manage Roles
- ✅ Send Messages
- ✅ Embed Links
- ✅ Read Message History
- Copy & paste the generated link into your browser.
- Select your Discord server and click Authorize.
Enable Privileged Intents
- Go to Discord Developer Portal.
- Select your bot application.
- Navigate to
Bot
in the left sidebar. - Scroll down to
Privileged Gateway Intents
. - Enable the following:
- ✅ Presence Intent
- ✅ Server Members Intent
- ✅ Message Content Intent
- Click Save Changes.
Ensure Correct Role Permissions
- Go to Server Settings →
Roles
. - Drag the bot’s role ABOVE the role it needs to assign.
- Ensure the bot has these permissions:
- ✅ Manage Roles
- ✅ Read Messages
- ✅ Send Messages
2️⃣ Installation Guide
1. Install System Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-pip python3-venv -y
2. Clone the Repository
git clone https://code.rustysats.com/saulteafarmer/discord-lnbits-bot
cd discord-lnbits-bot
3. Create & Activate Virtual Environment
python3 -m venv venv
source venv/bin/activate
4. Install Dependencies
pip install -r requirements.txt
3️⃣ Find Your Discord Guild ID & Role ID
Before configuring the bot, retrieve your Guild ID and Role ID.
🔹 How to Find Your Guild ID (Server ID):
- Open Discord → Go to User Settings (⚙️).
- Scroll down to Advanced → Enable Developer Mode.
- Right-click your server name (left sidebar) → Click Copy ID.
- Save this ID for later (
guild_id
).
🔹 How to Find Your Role ID:
- Open your Discord Server.
- Go to Server Settings → Roles.
- Right-click on the role you want to assign → Click Copy ID.
- Save this ID for later (
role_id
).
4️⃣ Configure the Bot
Edit the config.json
file inside the bot directory:
sudo nano config.json
{
"discord_token": "YOUR_DISCORD_BOT_TOKEN",
"guild_id": "YOUR_GUILD_ID",
"role_id": "YOUR_ROLE_ID",
"lnbits_url": "https://sats.love",
"lnbits_api_key": "YOUR_INVOICE_READ_KEY",
"price": 1000,
"command_name": "support",
"check_interval": 30,
"max_checks": 20
}
🔹 What Each Setting Does:
discord_token
→ Your bot token from Discord Developer Portalguild_id
→ Your Discord server IDrole_id
→ The Discord role the bot will assignlnbits_url
→ Base URL of your LNbits instancelnbits_api_key
→ Invoice-only key from LNbits (⚠️ NOT an admin key)price
→ Price in satoshis (e.g.,1000
= 1000 sats)command_name
→ Name of the command (default:support
)check_interval
→ How often (in seconds) the bot checks for paymentsmax_checks
→ How many times the bot will check before stopping
5️⃣ Run the Bot
python3 discord_lnbits_bot.py
6️⃣ Running the Bot in the Background
nohup python3 discord_lnbits_bot.py &
🔹 To stop the bot:
pkill -f discord_lnbits_bot.py
License
This project is open-source and free to use. Contributions welcome!
Languages
Python
100%