EN ▾
Get API key

Uncensored API for developers

Uncensored API for developers

Claude Code Discord Bot Alternative: Build Your Own

Updated

Chat bubbles linked to a server hub, illustrating an LLM-powered Discord bot

Claude Code is Anthropic's terminal coding tool, not a Discord bot framework. If you want a Discord bot that answers with an LLM, you build a small bot that calls a chat API, and the code below does that in about 60 lines.

Claude Code and Discord: what fits and what does not

People searching for a claude code discord bot tend to mean one of two things. Some want to drive Claude Code, Anthropic's command-line coding agent, from a Discord channel. Others want a chat bot in their server powered by a Claude-style model. The first is a project of its own: you run the CLI on a machine you control and relay messages to it, and you follow Anthropic's terms for that tool. We cannot help with it, and this service is not Anthropic's API.

The second is simple, and it is what the rest of this page builds. A Discord bot receives a message, sends the recent conversation to a chat completions endpoint, and posts the reply. Our endpoint is OpenAI-compatible and tuned not to refuse for lawful adult use, which suits fiction, roleplay and companion bots in servers for adults. Claude Code itself speaks Anthropic's request format, so do not point it at this endpoint; use a normal SDK in your own bot instead.

Before you start

You need three things: a Discord application with a bot token, an API key for this service, and Python 3.9 or newer.

  1. In the Discord Developer Portal, create an application, add a bot and copy its token. Under Privileged Gateway Intents, turn on Message Content Intent, otherwise the bot sees empty messages.
  2. Invite the bot to your server with the bot scope and permission to read and send messages.
  3. Sign up here, claim $0.50 of trial credit on the key page, and copy the key.

Check the key with curl before writing any bot code. A failure here is much easier to read than one inside an event loop.

curl https://api.claudeuncensored.cc/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Reply with the word ready."}],"max_tokens":5}'

The bot, step by step

The code uses discord.py and the async client from the openai package. It reacts only when the bot is mentioned, keeps the last 16 messages per channel as context, and caps replies at 500 tokens.

import asyncio
import os
from collections import defaultdict, deque

import discord
from openai import AsyncOpenAI, RateLimitError

ai = AsyncOpenAI(base_url="https://api.claudeuncensored.cc/v1", api_key=os.environ["API_KEY"])

SYSTEM = (
    "You are Vesper, a dry-witted narrator for a fiction server. "
    "Stay in character, keep replies under 250 words, and never write content "
    "involving minors."
)

intents = discord.Intents.default()
intents.message_content = True      # also enable it in the Developer Portal
bot = discord.Client(intents=intents)

history = defaultdict(lambda: deque(maxlen=16))   # last 16 messages per channel
slots = asyncio.Semaphore(6)                      # stay under 8 concurrent requests


async def complete(messages):
    for attempt in range(3):
        try:
            async with slots:
                r = await ai.chat.completions.create(
                    model="uncensored",
                    messages=messages,
                    temperature=0.9,
                    max_tokens=500,
                )
            return r.choices[0].message.content or ""
        except RateLimitError:
            await asyncio.sleep(5)
    return "The narrator is busy. Try again in a moment."


@bot.event
async def on_message(message):
    if message.author.bot or bot.user not in message.mentions:
        return

    text = message.content.replace(f"<@{bot.user.id}>", "").strip()
    if not text:
        return

    buf = history[message.channel.id]
    buf.append({"role": "user", "content": f"{message.author.display_name}: {text}"})

    async with message.channel.typing():
        reply = await complete([{"role": "system", "content": SYSTEM}] + list(buf))

    reply = reply or "..."
    buf.append({"role": "assistant", "content": reply})
    for i in range(0, len(reply), 1900):          # Discord caps messages at 2000 chars
        await message.channel.send(reply[i:i + 1900])


bot.run(os.environ["DISCORD_TOKEN"])

Install and run it:

pip install discord.py openai
export API_KEY="your-api-key"
export DISCORD_TOKEN="your-bot-token"
python bot.py

Mention the bot in a channel and it answers in the voice set by SYSTEM. Rewrite that prompt to change the persona. Everything about tone, setting and format belongs there, and the model follows it across turns because the whole short history is resent each time.

Design choices worth copying

One history per channel

The API holds no session state, so the bot stores messages itself. Prefixing each user line with the display name lets the model tell speakers apart in a shared channel. A bounded deque keeps the prompt from growing without limit.

No streaming to Discord

Streaming is supported by the API, but editing a Discord message on every chunk runs into Discord's own rate limits. A typing indicator followed by one full reply is simpler and feels fine for short answers.

A semaphore for concurrency

A full key allows 8 concurrent requests and 300 requests per minute; a trial key allows 2 and 60. Exceeding them returns HTTP 429 with concurrency or rate_limited. The semaphore set to 6 leaves headroom. While testing on a trial key, set it to 2. On temporary overload the API answers 429 with Retry-After: 5, which is why the retry sleeps five seconds.

Message length

Discord rejects messages over 2,000 characters. The loop splits at 1,900 so a long scene arrives as two posts instead of an error.

What it costs to run

Rates are $0.15 per 1M input tokens and $0.50 per 1M output tokens. Suppose your server triggers 1,000 replies a day, each with about 1,500 input tokens (system prompt plus 16 messages of history) and 250 output tokens. Daily input is 1.5M tokens, which is $0.225. Daily output is 0.25M tokens, which is $0.125. The day costs $0.35, and a 30-day month costs $10.50.

The cost scales with how much history you resend, not only with how often people talk. Cutting maxlen from 16 to 8 roughly halves the input side. Failed or refused requests are not billed, and credit never expires, so a quiet week costs nothing. Top-ups start at $20 and a $100 top-up adds a 10% bonus. See the pricing page for the tiers, and pay by crypto.

Running it responsibly

You are the operator, so the rules are yours to set. Discord's terms and community guidelines apply to your bot and your server, and adult-themed content belongs in channels and servers configured for adults. Sexual content involving minors is never allowed, and the system prompt above says so explicitly. Add your own moderation on top: a role check, a cooldown per user, and a command to clear a channel's history.

Keep tokens out of your repository, put API_KEY and DISCORD_TOKEN in environment variables, and read X-Balance-USD from the response headers if you want the bot to warn you when credit runs low. Prompts are not used for training. The docs cover the same call in curl and Node if you prefer discord.js.

Questions and answers

Can I run Claude Code inside Discord with this API?

No. Claude Code is Anthropic's tool and uses Anthropic's API format. This service is an independent OpenAI-compatible API, so you build a bot with a standard SDK instead.

Which library should I use?

Any Discord library works. The example uses discord.py with the async openai client; with discord.js you can use the openai Node package and the same base URL.

How many users can the bot serve at once?

A full key allows 8 concurrent requests and 300 per minute. Queue extra requests behind a semaphore and retry after five seconds on a 429.

Is it allowed to run an uncensored bot on Discord?

Discord's own rules apply to your bot, so keep adult content in appropriately configured channels. Sexual content involving minors is never permitted.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key