A ready-to-run starting point for building a Discord AI agent in Python. If you're looking for how to build a Discord bot that answers with an AI model, clone this template, add your bot token, plug in your model, and run — the messaging plumbing (gateway connection, replying in the right channel, deduping) is handled by Caspian, so all you write is one handler.
- Use this template — click "Use this template" at the top of this repo (or clone it), then
cdinto your new project. - Install dependencies:
pip install -r requirements.txt
- Get a Discord bot token — create an application at discord.com/developers, open the Bot tab, and copy the token. Invite the bot to your server from the OAuth2 tab.
- Get a Caspian API key — copy
.env.exampleto.env, then fill it in:Paste your bot token intocp .env.example .env pipx run caspian-cli init # writes your CASPIAN_API_KEYDISCORD_BOT_TOKENin the same.env. - Run it:
Message your bot on Discord — it replies. Now open
python main.py
main.pyand replace the placeholder inrespond()with your model call.
CommClient()readsCASPIAN_API_KEYandCASPIAN_BASE_URLfrom your environment or.env.client.connect_discord(bot_token=...)connects your bot — no gateway server to host.- The
@client.on_messagehandler fires for every inbound message;message.textis what the user sent. message.reply(...)answers in the same channel.client.listen()runs the loop for the lifetime of your agent.
The template ships with an echo placeholder. In main.py, the respond(text) -> str function is the one spot to change:
def respond(text: str) -> str:
# PLUG YOUR LLM CALL HERE
reply = my_model.generate(text)
return replyIt's provider-neutral — use any model or agent framework you like.
The same handler works across every channel Caspian supports — you just add one more connect_* call. For example, to also answer on Telegram:
client.connect_telegram(bot_token=os.environ["TELEGRAM_BOT_TOKEN"])No new handler code. Email, Slack, WhatsApp, SMS, and more work the same way.
- Main repo: github.com/TryCaspian/caspian-sdk — star it if useful.
- Docs: trycaspianai.com
MIT — see LICENSE.