Discord bots: using the VIDAI Control Plane as the backend¶
Discord bots (built with discord.py, discord.js, or any gateway client) invoke an LLM inside their message-handler code. Point that call at the control plane and every reply your bot posts flows through us.
TL;DR (discord.py)¶
import os
import discord
from openai import OpenAI
client = OpenAI(
base_url="https://your-vidai-server.example.com/v1",
api_key="your-vidai-key",
)
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
@bot.event
async def on_message(msg):
if msg.author == bot.user or not bot.user.mentioned_in(msg):
return
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": msg.content}],
)
await msg.channel.send(resp.choices[0].message.content)
bot.run(os.environ["DISCORD_TOKEN"])
Prerequisites¶
- A Discord application with a bot user (created at discord.com/developers).
- The Message Content intent enabled on the bot.
- Control plane base URL and an API key from API Keys.
- A model registered on the Models page.
Slash commands¶
For slash-command bots, use the interaction handler:
tree = discord.app_commands.CommandTree(bot)
@tree.command(name="ask", description="Ask the bot")
async def ask(interaction: discord.Interaction, prompt: str):
await interaction.response.defer()
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
)
await interaction.followup.send(resp.choices[0].message.content)
Threads¶
Discord threads work like Slack thread_ts — key your history
dict on msg.channel.id when the channel is a Thread.
Attribution¶
One VIDAI API key per bot. If your bot is installed to many servers, mint keys per server (or per customer) so Chargeback splits per install.
Verify it works¶
Mention the bot:
The bot posts ok. A row appears on
Request Logs.
If something's off¶
Raise an issue at github.com/vidaiUK/vidai-quickstart/issues with the bot's handler code (masking key) and the failing Discord message. We'll get it sorted.