This is a beginner-friendly overview of how I set up a Discord bot that acts as a front-end for an AI model. The bot lives in my Discord server, and when I message it, it responds using an AI of my choice (I used DeepSeek R1 0528, but you can use Claude, GPT, Gemini, Llama, etc. — anything available on OpenRouter).
What you'll need:
You type in Discord → Bot picks up your message → Sends it to OpenRouter API →
OpenRouter routes it to your chosen AI model → AI responds → Bot posts the reply in DiscordThat's it. The bot is just a messenger between you and the AI.
bot under ScopesDon't have a server? Just hit the + button in Discord's sidebar and make one.
Your bot should now appear in your server's member list (offline — it has no brain yet).
Open your terminal (Command Prompt on Windows, Terminal on Mac) and run:
python -m pip install discord.py requestsIf you're adding memory with Supabase, also run:
python -m pip install supabaseCreate a Python file (e.g., bot.py) with the following structure:
/api/v1/chat/completions endpoint, and posts the AI's response back into DiscordThe OpenRouter API call looks something like this:
response = requests.post(
"https://openrouter.ai/api/v1/chat/completions",
headers={"Authorization": f"Bearer {YOUR_OPENROUTER_KEY}"},
json={
"model": "deepseek/deepseek-r1-0528", # swap for any model
"messages": [
{"role": "system", "content": "Your system prompt here"},
{"role": "user", "content": "The user's message"}
],
"temperature": 0.7,
"max_tokens": 2048
}
)You have full control over the system prompt and all sampling parameters — same as using any AI API directly.
Without a database, your bot forgets everything when you restart it. With Supabase:
messages with columns: id, channel_id, role, content, created_atThis gives your bot real conversation memory that survives restarts.
python bot.pyKeep the terminal open — the bot is alive as long as the script is running. You'll see a message like "Bot is ready!" and your bot will show as online in Discord.
<think> tags in its responses (chain-of-thought reasoning). You'll want to strip those before posting to Discord with a simple regexBuilt with help from Claude. If you get stuck on any step, genuinely just ask an AI to walk you through it — they're great at this kind of thing.