TTS Bot for Discord with an LLM Script Backend
A tts bot for discord needs two parts: something that writes the lines and something that speaks them. This article covers the writing half with a hosted, OpenAI-compatible text API, and shows where the voice comes from.
Updated

Key points
- The API returns text only. Speech comes from Discord's own /tts feature or a separate speech engine.
- Point the OpenAI SDK at the base URL, use model uncensored, and the bot works with a few lines of discord.js.
- Keep a queue: a full key allows 8 requests at once and 300 per minute.
- A typical spoken line costs a fraction of a cent, so $20 of credit covers tens of thousands of lines.
What the model does and what it does not
For a tts bot for discord, the service on this site is a text model behind an OpenAI-compatible endpoint. You send chat messages to POST /v1/chat/completions with the model ID uncensored and you get text back. It does not generate audio, so it cannot be the voice of your bot. What it can do is write the lines: greetings, banter, in-character answers, narration for a roleplay scene, short announcements for a community voice channel.
That division of labour is common. Most bots that talk in a voice channel already split the work into a script step and a speech step, because the two problems are different. A speech engine is judged on how a voice sounds. A script writer is judged on whether the words fit the character and the moment. Keeping them apart lets you swap either one without touching the other.
The model is a single open-weight model run by an independent provider and tuned to answer without content refusals for lawful adult use. It is not the official API of any model maker. That matters for community bots in one practical way: a character who stays in role is easier to build when the backend does not break the scene with a refusal in the middle of a sentence. The hard limit is the same everywhere on the service: nothing sexual involving minors, ever.
If you want the broader picture of how text and voice fit together, the page on using a text LLM API in a TTS workflow covers it from the pipeline side. This article stays on Discord.
The three ways a bot can speak
Before writing code, choose how the sound reaches the server. There are three common routes, and the choice decides how much extra work you take on.
- Discord's built-in text-to-speech. A message sent with the TTS flag is read aloud by the Discord client for people who have that feature enabled and who are looking at the channel. The bot needs the permission to send TTS messages. There is no audio file, no voice connection and no extra service. The voice is whatever the listener's client provides, so you cannot pick it.
- A voice-channel bot with a speech engine. The bot joins a voice channel, turns each line into audio with an engine you choose, and plays the audio stream. You control the voice, but you now run an audio pipeline. In discord.js this is done with the
@discordjs/voicepackage. - A pre-rendered clip. The bot generates audio for a line, uploads the file to a text channel, and people press play. It is the simplest way to add a real voice without a live voice connection.
For a first version, use the first route. It lets you test the whole loop of message in, line written, line spoken, with about forty lines of code. The model call is identical in all three routes, so nothing you write now is wasted if you move to a voice-channel bot later.
A system prompt that writes for the ear
Text written for reading sounds odd when spoken. Lists, parentheses, markdown and long clauses all trip up a speech engine. The fix is a system prompt that tells the model it is writing for the ear. Here is one for a character called Mara:
You write short spoken lines for a Discord voice character called Mara.
Rules:
- Reply with one to three sentences, plain text only, no markdown, no emoji.
- Write for the ear: short words, no lists, no URLs, no abbreviations.
- Stay in character. Mara is dry, quick and a little theatrical.
- If asked for something outside lawful adult use, or anything involving minors, answer with one calm sentence declining.
Three details do most of the work. The length limit keeps latency and spoken time short; nobody wants a forty-second monologue in a voice channel. The "no emoji, no markdown" rule stops the speech engine from reading symbols aloud. The last rule gives the model a calm way out when a user pushes the character toward something you do not want, which is better than letting it improvise.
Set temperature around 0.7 to 0.9 for banter and lower for announcements that should stay predictable. The API passes temperature, top_p, stop, seed and the penalties through to the model, so you can pin a seed while testing to compare prompt changes fairly. If a character keeps repeating the same catchphrase, a small frequency penalty usually helps more than a longer prompt.
The bot: discord.js plus the OpenAI SDK
Install the two packages with npm install discord.js openai. Create an API key on the API key page, store it as NSFWTTS_KEY, and add your Discord bot token as DISCORD_TOKEN. Turn on the Message Content intent for the bot in the Discord developer portal, otherwise msg.content arrives empty.
The bot below answers any message that starts with say followed by a space. It keeps the last twenty messages per channel as context, asks the model for a short line, and posts it with the TTS flag set.
import { Client, GatewayIntentBits } from "discord.js";
import OpenAI from "openai";
const ai = new OpenAI({
baseURL: "https://api.nsfwtts.cc/v1",
apiKey: process.env.NSFWTTS_KEY,
});
const SYSTEM = process.env.MARA_PROMPT; // the system prompt from above
const history = new Map(); // channel id -> recent messages
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.on("messageCreate", async (msg) => {
if (msg.author.bot || msg.content.startsWith("say ") === false) return;
const past = history.get(msg.channelId) ?? [];
past.push({ role: "user", content: msg.content.slice(4).trim() });
try {
const res = await ai.chat.completions.create({
model: "uncensored",
messages: [{ role: "system", content: SYSTEM }, ...past.slice(-20)],
max_tokens: 200,
temperature: 0.8,
});
const line = res.choices[0].message.content.trim();
past.push({ role: "assistant", content: line });
history.set(msg.channelId, past.slice(-20));
await msg.channel.send({ content: line.slice(0, 1900), tts: true });
} catch (err) {
console.error(err.status, err.message);
await msg.reply("Mara lost her place. Try again in a few seconds.");
}
});
client.login(process.env.DISCORD_TOKEN);
The only changes from a stock OpenAI client are the baseURL and the key. Everything else is the normal Chat Completions call. If you prefer to test the endpoint before wiring up Discord, the same request works from a terminal:
curl https://api.nsfwtts.cc/v1/chat/completions \
-H "Authorization: Bearer $NSFWTTS_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"max_tokens": 200,
"messages": [
{"role": "system", "content": "You write short spoken lines for a Discord character called Mara. One to three sentences, plain text."},
{"role": "user", "content": "Welcome the next person who joins the voice channel."}
]
}'
The response includes an X-Balance-USD header, which is handy for a small admin command that tells you how much credit is left. The docs list the other headers and the full parameter set.
Limits, queues and what 429 means
A full key allows 8 requests at once and 300 per minute. A trial key allows 2 at once and 60 per minute. A single quiet server will never touch those numbers, but a bot that reacts to every join, every message or every reaction can, especially in a busy event channel.
When you go over, the API answers with HTTP 429. The error code tells you which limit you hit: rate_limited means too many requests per minute, and concurrency means too many at the same moment. A temporary overload also returns 429, with a Retry-After: 5 header. The OpenAI SDK retries a couple of times by default, but for a bot it is cleaner to avoid the problem with a small gate that never lets more than a fixed number of calls run together:
import OpenAI from "openai";
const ai = new OpenAI({ baseURL: "https://api.nsfwtts.cc/v1", apiKey: process.env.NSFWTTS_KEY });
const MAX_IN_FLIGHT = 6; // stay under the limit of 8 at once
let active = 0;
const waiting = [];
async function slot() {
if (active < MAX_IN_FLIGHT) { active++; return; }
await new Promise((resolve) => waiting.push(resolve));
active++;
}
function release() {
active--;
waiting.shift()?.();
}
export async function writeLine(messages) {
await slot();
try {
const res = await ai.chat.completions.create({ model: "uncensored", messages, max_tokens: 200 });
return res.choices[0].message.content.trim();
} finally {
release();
}
}
The gate keeps six calls in flight, which leaves headroom under the limit of eight. If you later add streaming, remember that a streamed request holds its slot until the stream ends, not until the first token arrives.
Context is large, but you rarely need it
The context window is 100,000 tokens, prompt plus completion. A voice bot almost never needs that much. Spoken lines are short and old chatter stops mattering quickly, so trimming to the last ten or twenty messages keeps both cost and latency low. The big window is useful for a different pattern: loading a long character sheet or a lore document once into the system prompt so the character stays consistent across a whole campaign.
What it costs to run
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, billed from prepaid credit. Failed or refused requests are not charged. Take a typical call from the bot above: about 2,000 input tokens (system prompt plus twenty messages of history) and 150 output tokens for the spoken line.
- Input: 2,000 tokens x $0.15 / 1,000,000 = $0.0003
- Output: 150 tokens x $0.50 / 1,000,000 = $0.000075
- One line: $0.000375
- 10,000 lines in a month: 10,000 x $0.000375 = $3.75
The smallest top-up is $20, which at this rate is roughly 53,000 lines. Credit never expires, so an unused balance simply waits. This site accepts crypto top-ups only (USDT on TRC20 or USDC on Base), with a bonus of 5% from $50, 10% from $100 and 15% from $200. Current details are on the pricing page.
New accounts can claim $0.50 of trial credit with one click on the key page after sign-up. It needs no payment and lasts 7 days. At the rate above that is over 1,300 test lines, enough to tune a character before you spend anything.
Rules for a community bot
The model is tuned for lawful adult use, and the rest is up to the operator. If your server hosts mature fiction or companion-style roleplay, keep the bot to channels that are marked for adults according to Discord's own rules, and read those rules before you launch. Prompts are not used for training on this service, but the messages your members type are still their messages, so tell them a bot reads the channel.
Do not let the bot fabricate a real person speaking. Writing lines for an invented character is fine. Putting words in the mouth of a named real person and then voicing them is a different matter, and a good reason to keep a clear label on the bot. And as stated above, anything sexual involving minors is not allowed, with no exceptions.
Last, treat the TTS flag with care. Spoken messages interrupt people, so give the command a cooldown per user and keep lines short. A bot that reads a paragraph aloud every few seconds will get muted or removed fast.
More guides
Questions and answers
Can the API itself produce the voice for a Discord bot?
No. It is a text-only model. It writes the script, and Discord's TTS flag or a separate speech engine turns that script into sound.
Which model ID do I use with the OpenAI SDK?
Use uncensored as the model, set the base URL to https://api.nsfwtts.cc/v1, and pass your key as a Bearer token. The SDK handles the rest.
How many Discord servers can one key handle?
The limit is per key, not per server: 8 concurrent requests and 300 per minute on a full key. Put a queue in front of the API and a cooldown on the command.
Can I test the bot without paying?
Yes. After sign-up you can claim $0.50 of trial credit with one click on the API key page. It is valid for 7 days, needs no payment, and the trial key allows 2 concurrent requests.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.