# 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** (configurable), and the bot automatically assigns the role **once payment is confirmed**. --- ## πŸš€ Features - βœ… Dynamic slash‐command name (configured via `command_name`) - βœ… Generates a **Lightning invoice** via LNbits - βœ… Listens on LNbits WebSocket for paid invoices - βœ… Automatically assigns a **Discord role** on payment - βœ… Posts confirmations directly in your designated channel --- ## πŸ“‹ Requirements - **Ubuntu 24.04** - **Python 3.10+** - **A Discord Bot Token** (from the [Developer Portal](https://discord.com/developers/applications)) - **LNbits Wallet Invoice Key** - **A running LNbits instance** (e.g., [Sats.Love](https://sats.love/)) --- ## 1️⃣ Setting Up Your Bot ### Generate a Proper Bot Invite Link 1. **Go to**: [Discord Developer Portal](https://discord.com/developers/applications) 2. **Click New Application** 3. Go to **OAuth2 > URL Generator** 4. **Check these Scopes**: - βœ… **bot** - βœ… **applications.commands** (for slash commands) 4. **Under Bot Permissions**, check: - βœ… **Manage Roles** - βœ… **Send Messages** - βœ… **Embed Links** - βœ… **Read Message History** 5. **Copy & paste the generated link into your browser.** 6. **Select your Discord server** and click **Authorize**. --- ### Enable Privileged Intents 1. **Go to** [Discord Developer Portal](https://discord.com/developers/applications). 2. **Select your bot application.** 3. **Navigate to** `Bot` in the left sidebar. 4. **Scroll down to** `Privileged Gateway Intents`. 5. **Enable** the following: - βœ… **Presence Intent** - βœ… **Server Members Intent** - βœ… **Message Content Intent** 6. **Click Save Changes.** --- ### Ensure Correct Role Permissions 1. **Go to Server Settings** β†’ `Roles`. 2. **Drag the bot’s role ABOVE** the role it needs to assign. 3. **Ensure the bot has these permissions**: - βœ… **Manage Roles** - βœ… **Read Messages** - βœ… **Send Messages** --- ## 2️⃣ Installation Guide ### 1. Install System Dependencies ```bash sudo apt update && sudo apt upgrade -y sudo apt install python3 python3-pip python3-venv -y ``` ### 2. Clone the Repository ```bash git clone https://code.rustysats.com/saulteafarmer/discord-lnbits-bot cd discord-lnbits-bot ``` ### 3. Create & Activate Virtual Environment ```bash python3 -m venv venv source venv/bin/activate ``` ### 4. Install Dependencies ```bash 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): 1. Open **Discord** β†’ Go to **User Settings** (βš™οΈ). 2. Scroll down to **Advanced** β†’ Enable **Developer Mode**. 3. **Right-click your server name** (left sidebar) β†’ Click **Copy ID**. 4. **Save this ID** for later (`guild_id`). ### πŸ”Ή How to Find Your Role ID: 1. Open your **Discord Server**. 2. Go to **Server Settings** β†’ **Roles**. 3. **Right-click on the role** you want to assign β†’ Click **Copy ID**. 4. **Save this ID** for later (`role_id`). --- ## 4️⃣ Configure the Bot Edit the `config.json` file inside the bot directory: ```bash sudo nano config.json ``` ```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", "channelid": "YOUR_CHANNELID_FOR_PURCHASE_ROOM", "price": 1000, "command_name": "support", "invoicemessage": "Invoice for your purchase." } ``` ### πŸ”Ή What Each Setting Does: - **`discord_token`** β†’ Your bot token from Discord Developer Portal - **`guild_id`** β†’ Your Discord server ID - **`role_id`** β†’ The Discord role the bot will assign - **`lnbits_url`** β†’ Base URL of your LNbits instance - **`lnbits_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`) - **`invoicemessage`** β†’ Message to be sent with invoice - **`channelid`** β†’ Discord channel where invoices and confirmations post --- ## 5️⃣ Run the Bot ```bash python3 discord_lnbits_bot.py ``` --- ## 6️⃣ Running the Bot in the Background ```bash nohup python3 discord_lnbits_bot.py & ``` πŸ”Ή **To stop the bot**: ```bash pkill -f discord_lnbits_bot.py ``` --- ## License This project is **open-source** and free to use. Contributions welcome!