Discord AI Bot Framework for an Uncensored LLM
If you are choosing a discord ai bot framework, the model backend matters less than the loop around it: listen, keep history, call the API, split the reply. This guide builds that loop on an OpenAI-compatible endpoint.
Updated

What a framework gives you and what you still write
People who search for a Discord AI bot framework usually want one of two things. The first is a library that talks to Discord: gateway connection, events, slash commands, permissions. The second is a ready-made bot project with memory, personas and settings already wired up. Both exist, and both end at the same place: a function that takes a list of chat messages and returns text.
That function is the only part that touches the language model. This API follows the OpenAI chat format, so the function is a standard POST /v1/chat/completions request. You set the base URL to https://api.nsfwgpt.cc/v1, send your key as a bearer token, and use uncensored as the model ID. Everything else in the bot, from commands to storage, is ordinary Discord work.
It helps to be clear about what you are building before you pick tools. A bot that answers mentions in one channel needs perhaps sixty lines. A bot with per-user personas, slash commands, a database and moderation hooks is a real project, and a framework with a plugin system starts to pay off. Most hobby servers sit near the small end, and that is where this article stays.
Pick the library first
Two libraries cover most cases. discord.py is the long-standing Python option and works well with asyncio, which suits an API client that waits on the network. discord.js is the Node equivalent. Either one can call the model through the official OpenAI SDK for its language, because the SDKs accept a custom base URL.
- discord.py plus the Python openai SDK. Good if you already script in Python or want to add data tools later. The async client keeps the bot responsive while a reply streams in.
- discord.js plus the Node openai package. Good if the rest of your stack is JavaScript or TypeScript.
- A ready-made bot project. Many open source bots let you set an OpenAI-compatible endpoint in a config file or environment variables. If one of them fits your needs, you only supply the base URL, the key and the model ID. Check that project's own documentation for the setting names.
Do not pick by model support. Pick by the language you can maintain at 2 a.m. when the bot misbehaves. The Node version of the call looks like this:
import OpenAI from "openai";
const ai = new OpenAI({
baseURL: "https://api.nsfwgpt.cc/v1",
apiKey: process.env.NSFWGPT_KEY,
});
export async function reply(history) {
const res = await ai.chat.completions.create({
model: "uncensored",
messages: [{ role: "system", content: "You are Mara, a narrator for adults." }, ...history],
temperature: 0.9,
max_tokens: 500,
});
return res.choices[0].message.content;
}A working bot in Python
First test the endpoint outside Discord, so you know the key and URL are right. A single request should return JSON with a reply in choices[0].message.content.
curl https://api.nsfwgpt.cc/v1/chat/completions \
-H "Authorization: Bearer $NSFWGPT_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"uncensored","messages":[{"role":"user","content":"Say hello in one line."}],"max_tokens":40}'Then create a bot in the Discord developer portal, enable the Message Content intent for it, invite it to your server, and export two environment variables: DISCORD_TOKEN and NSFWGPT_KEY. This is a complete bot that answers when it is mentioned:
import asyncio, os
import discord
from openai import AsyncOpenAI, RateLimitError
ai = AsyncOpenAI(base_url="https://api.nsfwgpt.cc/v1", api_key=os.environ["NSFWGPT_KEY"])
SYSTEM = (
"You are Mara, a dry-witted narrator for an adults-only fiction server. "
"Stay in character. Keep each reply under 1200 characters."
)
slots = asyncio.Semaphore(6) # stay under the 8 concurrent requests of a full key
history = {} # channel id -> list of messages
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
async def ask(log):
for attempt in range(4):
try:
r = await ai.chat.completions.create(
model="uncensored",
messages=[{"role": "system", "content": SYSTEM}, *log],
temperature=0.9,
max_tokens=500,
)
return r.choices[0].message.content
except RateLimitError:
await asyncio.sleep(5 * (attempt + 1))
return "Busy right now. Try again in a moment."
@bot.event
async def on_message(msg):
if msg.author.bot or bot.user not in msg.mentions:
return
log = history.setdefault(msg.channel.id, [])
text = msg.clean_content.replace("@" + bot.user.name, "").strip()
log.append({"role": "user", "content": msg.author.display_name + ": " + text})
del log[:-12]
async with slots:
async with msg.channel.typing():
reply = await ask(log)
log.append({"role": "assistant", "content": reply})
for i in range(0, len(reply), 1900):
await msg.channel.send(reply[i:i + 1900])
bot.run(os.environ["DISCORD_TOKEN"])Three details are worth a second look. The semaphore keeps the bot from firing more than six requests at once. The del log[:-12] line drops everything but the last twelve messages in a channel. And the reply is sent in slices of 1,900 characters, because Discord rejects messages longer than 2,000.
System prompt and per-channel memory
The system prompt is where the bot gets its character. Write it like a brief to a new actor: who the bot is, how it speaks, what it should avoid, how long its answers should be. A short, specific prompt beats a long list of rules. If the server is for fiction or roleplay between adults, say so in the prompt and name the tone you want.
Memory is just the list you resend with every request. The model does not remember earlier calls, so the bot keeps the recent messages and sends them again. The context window is 100,000 tokens for prompt plus completion, which is far more than a Discord channel needs. The limit you will actually feel is cost and speed: every old message is billed as input on every new turn.
A few habits keep memory useful:
- Prefix each user message with the display name, as in the code above, so the model can tell speakers apart in a busy channel.
- Keep one history per channel, or per thread, never one global list.
- Store a short summary of older events as a second system message if your story runs for weeks, and let the last ten or twelve messages carry the live scene.
- Give users a reset command that clears the list. Characters drift, and a clean start is the easiest fix.
Sampling settings pass straight through. For storytelling, a temperature around 0.8 to 1.0 gives variety. For a utility bot that formats or classifies text, drop it near 0.2. If you want repeatable output while testing, set seed.
Concurrency, 429 errors and the 2,000 character limit
A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent and 60 per minute. A lively server can easily send several messages in the same second, so decide in advance what happens when the limit is hit.
The API answers with HTTP 429 in two cases. The error code rate_limited means too many requests per minute, and concurrency means too many at once. A temporary overload also returns 429, with a Retry-After: 5 header. The OpenAI SDKs retry 429 responses a couple of times by default, and the loop in the bot adds a longer wait on top of that. Failed requests are not charged, so retrying costs nothing extra.
Streaming deserves a warning. A streamed request holds its concurrency slot until the stream ends. If you stream into Discord by editing a message every second, a long reply keeps a slot busy for its whole length. For a small server that is fine. For a large one, use plain non-streamed replies behind the typing indicator, and keep streaming for a web front end.
On the Discord side, keep max_tokens near 400 to 600 for chat replies and tell the model a target length in the system prompt. That keeps most answers inside one message, and the slicing loop handles the rest.
Tool calling and JSON mode for game bots
The API supports tool calling, so a bot can do more than talk. A dice roller, a character sheet lookup or an inventory update can be exposed as a function. You describe the function in tools, the model returns a tool_calls entry when it wants it, your code runs it, and you send the result back as a message with role: "tool".
tools = [{
"type": "function",
"function": {
"name": "roll_dice",
"description": "Roll dice for a game scene.",
"parameters": {
"type": "object",
"properties": {"sides": {"type": "integer"}, "count": {"type": "integer"}},
"required": ["sides"],
},
},
}]
r = await ai.chat.completions.create(
model="uncensored", messages=messages, tools=tools, tool_choice="auto"
)
call = r.choices[0].message.tool_callsJSON mode is the other useful feature. Set response_format to {"type": "json_object"} and ask for a specific shape in the prompt, for example a scene description with a list of choices. Parse the result with a try block anyway. A model can still return a shape you did not intend, and the bot should survive that.
The limits are plain. The model produces text only: no images, no voice, no embeddings. If your server wants pictures or speech, you need a separate service for those and a way to pass the text between them.
Cost and server rules
Price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, paid from prepaid credit. Take a bot that sends a 600-token system prompt plus about 900 tokens of recent history, so 1,500 input tokens, and gets a 250-token reply. Input costs 1,500 x $0.15 / 1,000,000 = $0.000225. Output costs 250 x $0.50 / 1,000,000 = $0.000125. One reply costs $0.00035, so 1,000 replies cost $0.35. A server that gets 300 replies a day spends about $0.105 a day, or roughly $3.15 over thirty days.
Top-ups on this site are crypto only: USDT on TRC20 or USDC on Base, any whole amount from $20 to $500, with a bonus of 5% from $50, 10% from $100 and 15% from $200. Credit never expires, so a $20 balance can sit under a small bot for months. New users can also claim $0.50 of trial credit with one click on the API key page, valid for 7 days. The pricing page has the full table, and getting a key takes a few minutes.
Two rules apply outside the code. Discord lets you mark channels as age-restricted, and an adults-only bot belongs only in channels set up that way. And the service allows lawful adult use only; sexual content involving minors is not permitted, so build that rule into your server rules and your system prompt. For the request format and other parameters, see the quickstart, and for a broader integration walkthrough read the integration guide.
More guides
Start with trial credit
Email and password, key on screen right away.
Questions and answers
Which library is best for a Discord AI bot?
Use the one in your strongest language. discord.py with the Python openai SDK and discord.js with the Node openai package both work, since each only needs the base URL, key and model ID changed.
How do I give the bot a memory?
Keep the last 10 to 12 messages per channel in a list and send them with every request, after the system prompt. The model itself stores nothing between calls.
What happens when many users write at once?
Requests above 8 at the same time on a full key return HTTP 429 with the code concurrency. Use a semaphore and retry after a short pause; failed requests are not charged.
Can the bot send images or voice?
No. The model is text only, with no image, audio or video generation. You can only pass its text to other services you run yourself.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.