How to build an AI Discord bot with Vikasit AI
An AI Discord bot listens for messages or slash commands and replies using an LLM. Combine discord.py with the Vikasit API to add a smart assistant to any server.
Recommended model
Vikasit 3 Flash
Fast, cheap responses keep chat snappy and costs low for high-message-volume servers. Use Vikasit 3 for richer replies.
Steps
- 1
Create a Discord application and bot token in the Discord developer portal.
- 2
Install discord.py and the OpenAI SDK.
- 3
Connect the bot and listen for messages or register slash commands.
- 4
On each prompt, call the Vikasit chat API with the user's message.
- 5
Send the model's reply back to the channel, respecting Discord's 2000-char limit.
- 6
Add per-user rate limits and a system prompt to keep the bot on-topic.
Code
The Vikasit Inference API is OpenAI-compatible, so this uses the standard OpenAI Python SDK pointed at https://api.vikasit.ai/v1.
import discord
from openai import OpenAI
client = OpenAI(
base_url="https://api.vikasit.ai/v1",
api_key="sk-vikasit-...", # get one at vikasit.ai/auth
)
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
resp = client.chat.completions.create(
model="vikasit-3-flash",
messages=[{"role": "user", "content": message.content}],
)
await message.channel.send(resp.choices[0].message.content[:2000])
bot.run("YOUR_DISCORD_TOKEN")Build your AI Discord bot today
Get an API key and 2M free tokens a day on Vikasit Nova. Pay-as-you-go, no minimums, OpenAI-compatible.