DEV Community

Nexus Intelligence Research
Nexus Intelligence Research

Posted on

🚀 Turn Your Discord Server Into a One‑Click AI‑Tool Marketplace with Stripe Checkout

Build a Python Discord bot that sells a PRO AI product, posts daily deals, and runs 24/7 on a VPS.

TL;DR – In this tutorial you’ll learn how to spin up a cheap VPS, install discord.py and Stripe, write a bot that generates a one‑time checkout link (!buypro), schedule daily posts to multiple channels, handle rate‑limits, test in Stripe’s sandbox, then go live and daemonise the bot. All in under an hour.


📚 Table of Contents

  1. Why Combine Discord, Stripe, and AI?
  2. What You’ll Need
  3. Step 1 – Provision a VPS (VPS2)
  4. Step 2 – Install Python & Dependencies
  5. Step 3 – Create discord_bot.py
  6. Step 4 – Hook Up Stripe Checkout
  7. Step 5 – Add the !buypro Command
  8. Step 6 – Schedule Daily Link Posts
  9. Step 7 – Rate‑Limit Friendly Posting
  10. Step 8 – Test in Stripe Test Mode
  11. Step 9 – Flip to Live Mode & Daemonise the Bot
  12. Wrap‑Up & Next Steps

Why Combine Discord, Stripe, and AI?

Discord is the de‑facto hub for AI enthusiasts, crypto traders, and data‑analysis hobbyists. By offering a PRO subscription (think premium prompts, custom models, or exclusive datasets) you can monetize a community you already own. Stripe gives you PCI‑compliant, one‑click checkout without ever handling raw card data. Pair them together, and you have a frictionless sales funnel that lives right inside the chat you already monitor.


What You’ll Need

Item Minimum Spec Recommended
VPS (VPS2) 1 vCPU, 512 MiB RAM, 10 GB SSD 1 vCPU, 1 GiB RAM, 20 GB SSD
OS Ubuntu 22.04 LTS (or any Debian‑based distro) Ubuntu 22.04 LTS
Python 3.9+ 3.11
Discord Bot Token Create a bot at the Discord Developer Portal —
Stripe Account Test mode API keys Live mode API keys
Channel IDs List of target channel IDs (e.g., 123456789012345678) —
Domain (optional) For webhook verification —

Affiliate note: I host my VPS on DigitalOcean – they offer a $100 credit for new users, perfect for testing this guide.


Step 1 – Provision a VPS (VPS2)

  1. Create a new droplet (or equivalent) on your provider’s dashboard.
  2. Choose the Ubuntu 22.04 LTS image.
  3. Set a strong root password or SSH key (highly recommended).
  4. Open port 22 for SSH and port 443 if you plan to expose a webhook later.
  5. Take note of the public IP – you’ll need it for SSH.
# Example SSH login
ssh root@YOUR_VPS_IP
Enter fullscreen mode Exit fullscreen mode

Step 2 – Install Python & Dependencies

# Update & install basics
apt update && apt upgrade -y
apt install -y python3-pip python3-venv git curl

# Create a virtual environment for isolation
python3 -m venv /opt/discord-bot
source /opt/discord-bot/bin/activate

# Install core libraries
pip install --upgrade pip
pip install discord.py==2.3.2 stripe==10.5.0 apscheduler
Enter fullscreen mode Exit fullscreen mode

Why apscheduler? It gives us a clean, timezone‑aware way to schedule daily posts without pulling in a full‑blown cron job.


Step 3 – Create discord_bot.py

Navigate to a working directory and create the file:

mkdir -p /opt/discord-bot/src
cd /opt/discord-bot/src
nano discord_bot.py
Enter fullscreen mode Exit fullscreen mode

Paste the skeleton below (you’ll fill in the Stripe part later):


python
#!/usr/bin/env python3
import os
import asyncio
import discord
import stripe
from datetime import datetime
from apscheduler.schedulers.asyncio import AsyncIOScheduler

# -------------------- Config --------------------
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")          # Set in env
STRIPE_SECRET_KEY = os.getenv("STRIPE_SECRET_KEY") # Set in env
PRO_PRODUCT_PRICE_ID = os.getenv("PRO_PRICE_ID")    # Stripe Price ID for PRO
CHANNEL_IDS = [int(cid) for cid in os.getenv("CHANNEL_IDS", "").split(",")]  # CSV list
# ------------------------------------------------

intents = discord.Intents.default()
client = discord.Client(intents=intents)

stripe.api_key = STRIPE_SECRET_KEY

def create_checkout_session():
    """Generate a one‑time checkout session for the PRO product."""
    session = stripe.checkout.Session.create(
        payment_method_types=["card"],
        line_items=[{
            "price": PRO_PRODUCT_PRICE_ID,
            "quantity": 1,
        }],
        mode="payment",
        success_url="https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}",
        cancel_url="https://yourdomain.com/cancel",
    )
    return session.url

@client.event
async def on_ready():
    print(f"🤖 Logged in as {client.user} (ID: {client.user.id})")
    # Start scheduler after bot is ready
    scheduler.start()

@client.event
async def on_message(message):
    # Ignore bot's own messages
    if message.author == client.user:
        return

    if message.content.lower().startswith('!buypro'):
        checkout_url = create_checkout_session()
        await message.reply(
            f"🚀 Grab your PRO access here: {checkout_url}\n"
            "Your link expires in 24 hours."
        )

# ---------------- Scheduler --------------------
scheduler = AsyncIOScheduler()

@scheduler.scheduled_job("cron", hour=9, minute=0)  # 09:00 UTC daily
async def post_daily_link():
    """Post the checkout link to every channel in CHANNEL_IDS."""
    url = create_checkout_session()
    for cid in CHANNEL_IDS:
        channel = client.get_channel(cid)
        if channel:
            try:
                await channel.send(f"đź”” **Daily PRO Deal**: {url}")
                await asyncio.sleep(2)  # Rate‑limit friendly
            except discord.HTTPException as e:
                print(f"❗️ Failed to post in {cid}: {e}")

# ------------------------------------------------
if __name__ == "__main__":
    client.run(DIS
Enter fullscreen mode Exit fullscreen mode

Top comments (0)