Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord AI Agent Template (Python)

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.

Quickstart (under 5 minutes)

  1. Use this template — click "Use this template" at the top of this repo (or clone it), then cd into your new project.
  2. Install dependencies:
    pip install -r requirements.txt
  3. 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.
  4. Get a Caspian API key — copy .env.example to .env, then fill it in:
    cp .env.example .env
    pipx run caspian-cli init   # writes your CASPIAN_API_KEY
    Paste your bot token into DISCORD_BOT_TOKEN in the same .env.
  5. Run it:
    python main.py
    Message your bot on Discord — it replies. Now open main.py and replace the placeholder in respond() with your model call.

How it works

  • CommClient() reads CASPIAN_API_KEY and CASPIAN_BASE_URL from your environment or .env.
  • client.connect_discord(bot_token=...) connects your bot — no gateway server to host.
  • The @client.on_message handler fires for every inbound message; message.text is what the user sent.
  • message.reply(...) answers in the same channel.
  • client.listen() runs the loop for the lifetime of your agent.

Plug in your model

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 reply

It's provider-neutral — use any model or agent framework you like.

Add more channels

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.

Links

License

MIT — see LICENSE.

Releases

Packages

Contributors

Languages