Build an AI Discord or Telegram bot
An AI bot for your clan, guild or community needs three things: a bot library that talks to Discord or Telegram, a cheap fast model for replies, and an always-on host. Bots hold a persistent connection, so serverless hosting is a poor fit. Use a small always-on container instead.
Recommended stack
Model
- Google Gemini 3.8 Flash: Free tier available; paid ~$0.75 in / $3.75 out per 1M until 2026-12-31, then $1.50/$7.50 (verified 2026-10-14)
- OpenAI GPT-6 Luna: ~$0.10 in / $0.50 out per 1M tokens (verified 2026-10-14)
Framework
- discord.js: Free, open source
- discord.py: Free, open source
- grammY (Telegram): Free, open source
Hosting
No-code alternative
- BotGhost (no-code Discord bots): Free tier + premium (not verified - check site)
- n8n: Self-host free (fair-code); cloud paid (not verified - check site)
Rough monthly cost
$0–10/mo (Railway Hobby $5 + light model usage)ApproximateDifficulty
Beginner–IntermediateSome links may be affiliate links. Disclosure
Why this stack
- discord.js (JavaScript) and discord.py (Python) are the two most widely used Discord libraries; grammY is a modern TypeScript framework for Telegram bots.
- Fast, low-cost models like Gemini Flash or GPT-6 Luna keep per-message cost tiny for chatty servers.
- Railway's Hobby plan or a small Fly.io machine can keep a bot process online 24/7 for a few dollars a month.
Step-by-step
- Create an application in the Discord Developer Portal (or talk to @BotFather on Telegram) and copy the token into an environment variable.
- Get a /ping slash command working before any AI.
- Add an /ask command that sends the message to your model with a short system prompt describing your community.
- Add per-user rate limits so one member can't burn your token budget.
- Deploy to Railway or Fly.io and watch logs for the first week.
Common pitfalls
- Never commit your bot token; rotate it if it leaks.
- Enable only the gateway intents you need (Message Content is privileged).
- Cap max output tokens; long replies get cut off by Discord's 2,000-character message limit.