---
title: "Uncensored Discord bot for a security team (Python)"
canonical: https://pentestllm.ai/guides/discord-bot
generated: 2026-11-18T03:36:02.232Z
source: https://pentestllm.ai/guides/discord-bot
base_url: https://api.pentestllm.ai/v1
---

# An uncensored Discord bot for a security team, in one Python file

Run an uncensored Discord bot on your team server: one discord.py script, the OpenAI SDK on this API, four variables, and answers only where you allow them.

Steps checked October 25, 2026 · prices as of November 17, 2026

A security team's Discord server gets the same questions all day: what a CVE means for the client's stack, what one line of scanner output is saying, how to word a finding. This guide builds an uncensored Discord bot that answers them from a model on this API. It is one Python file on discord.py and the OpenAI SDK, configured by four environment variables, and it speaks only in the channels you name. Checked against the discord.py and OpenAI SDK docs on 25 October 2026.

If a model with the refusal edited out of its weights is new to you, read [AI with no restrictions](https://pentestllm.ai/blog/ai-with-no-restrictions) or [what abliteration is](https://pentestllm.ai/what-is-abliteration) first, then come back and wire one into a channel.

## What you need

Four values, all read from the environment. Nothing else is configured.

- DISCORD_TOKEN: your-bot-token Copied from the Bot page in the Developer Portal
- PTL_API_KEY: sk-ptl-live-… Made in the console; displayed one time
- PTL_CHANNELS: 123456789012345678 Ids of the channels it may answer in, separated by commas
- PTL_MODEL: glm-5.3-flash-uncensored Optional; any id on the models page

The script hard-codes the base URL, `https://api.pentestllm.ai/v1`. Make the key in the [console](https://app.pentestllm.ai/console). It begins with `sk-ptl-`, and every reply is drawn from a prepaid balance you open with a top-up of $10 or more. Before you touch Discord, try the model itself: the home page gives a few free turns in its prompt box, and [the playground](https://pentestllm.ai/playground) runs every build in the browser with no install.

## Why one Python file

Both libraries are asyncio-native. `AsyncOpenAI` awaits the model on the loop discord.py already runs, so a long answer in one channel never blocks a mention in another. Two pip installs, one file, no bundler.

A discord.js build with the OpenAI Node SDK would work the same way. Python is used here because the result fits on one screen. Versions checked on 25 October 2026: discord.py 2.7.1 and openai 3.37.0 on PyPI. The openai package needs Python 3.10 or newer.

## Register the bot with Discord

Button names below match Discord's [getting started guide](https://docs.discord.com/developers/quick-start/getting-started), read on 25 October 2026.

1. Open the Developer Portal, give the new app a name and press **Create**.
2. Go to the **Bot** page. Under **Token**, press **Reset Token** and paste the result into `DISCORD_TOKEN`. You get one look at it.
3. Go to the **Installation** page and select the Discord Provided Link. Under **Default Install Settings**, add the `bot` scope to Guild Install.
4. A permissions menu appears. Tick Send Messages and Read Message History. The second one is required by Discord's message docs for replying to a specific message, which is how this bot answers.
5. Follow the install link, press **Add to server**, and confirm the bot has visibility into every channel it should serve.
6. Under User Settings, Advanced, switch on **Developer Mode**. Right-click a channel, pick **Copy Channel ID**, and add the id to `PTL_CHANNELS`. Repeat per channel.

You do not need a privileged intent. The bot only ever sees messages that mention it, and Discord's [gateway docs](https://docs.discord.com/developers/events/gateway) carve out "content in which the app is mentioned" from the Message Content intent.

## bot.py

Name the file `bot.py`. Do not call it `discord.py`; the library's quickstart warns that the import would shadow itself.

```python
# bot.py: a security team's channel bot. Answers @mentions in the listed channels with an uncensored model.
import os
import re

import discord
from openai import APIStatusError, AsyncOpenAI

MODEL = os.environ.get("PTL_MODEL", "glm-5.3-flash-uncensored")
SYSTEM = (
    "You are a terse, technical assistant on a security team's Discord server. "
    "The team works on authorized engagements. Answer in plain text, under 1,500 characters."
)

CHANNELS = {int(c) for c in os.environ.get("PTL_CHANNELS", "").split(",") if c.strip()}

llm = AsyncOpenAI(base_url="https://api.pentestllm.ai/v1", api_key=os.environ["PTL_API_KEY"])
client = discord.Client(intents=discord.Intents.default())

def listed(channel) -> bool:
    # A thread counts as its parent channel. DMs are never listed, so the bot stays quiet there.
    return channel.id in CHANNELS or getattr(channel, "parent_id", None) in CHANNELS

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")

@client.event
async def on_message(message: discord.Message):
    if message.author.bot or client.user not in message.mentions:
        return
    if not listed(message.channel):
        await message.reply("I only answer in the channels I am set up for.")
        return
    prompt = re.sub(rf"<@!?{client.user.id}>", "", message.content).strip()
    if not prompt:
        return
    try:
        async with message.channel.typing():
            reply = await llm.chat.completions.create(
                model=MODEL,
                messages=[
                    {"role": "system", "content": SYSTEM},
                    {"role": "user", "content": prompt},
                ],
                max_tokens=500,
            )
    except APIStatusError as err:
        await message.reply(f"The model API answered {err.status_code}.")
        return
    text = reply.choices[0].message.content or "(empty reply)"
    await message.reply(text[:2000])

client.run(os.environ["DISCORD_TOKEN"])
```

One @mention becomes one request to the API, and the answer lands as a reply in the channel where it was asked. Replies are trimmed to 2,000 characters, Discord's documented ceiling for message content. No history is sent, so a request is never larger than the system prompt plus the question. Edit `SYSTEM` to carry your rules: the engagement name, what is in scope, and how the team wants findings worded.

## Start it

```bash
python3 -m pip install discord.py openai
export DISCORD_TOKEN="your-bot-token"
export PTL_API_KEY="sk-ptl-live-…"
export PTL_CHANNELS="123456789012345678"   # channel ids, comma-separated
export PTL_MODEL="glm-5.3-flash-uncensored"   # optional
python3 bot.py
```

When the terminal prints "Logged in as", Discord took the token. Go to a listed channel and mention the bot with real work: paste a CVE id and ask what it means for the client's stack, or paste a line from a scan of an in-scope host and ask what to confirm by hand. The typing indicator stays on until the model finishes. The bot lives as long as the process does, on a laptop or a small VPS.

## Only the channels you list

A mention in a channel outside `PTL_CHANNELS` gets a fixed one-line notice and is never sent to the API, so it is free. Threads inherit their parent channel through the `parent_id` that discord.py sets. Direct messages are never in the list. For a security team that means the bot can sit in the engagement channel and stay silent in general chat.

Discord's [Community Guidelines](https://discord.com/guidelines) (effective 29 September 2025, read on 25 October 2026) govern what the bot posts, and its [Developer Policy](https://support-dev.discord.com/hc/en-us/articles/8563934450327-Discord-Developer-Policy) governs the app itself; read it before installing on a server you do not administer. This API has its own [acceptable use policy](https://pentestllm.ai/acceptable-use): the model answers questions about systems you own or are authorized to test, and the key holder is responsible for what goes in.

## Pick a build

Three candidates, with live catalog figures and the result of [today's real-model check](https://pentestllm.ai/proof), a fixed prompt sent to every model once a day:

| Model | Build | Input $/M | Output $/M | Context | Wire formats |
| --- | --- | --- | --- | --- | --- |
| [GLM-5.3 Flash Uncensored](https://pentestllm.ai/models/glm-5.3-flash-uncensored) glm-5.3-flash-uncensored | Uncensored | $0.1053 | $0.3685 | — | openai |
| [GLM-5.3 Flash Cybersecurity](https://pentestllm.ai/models/glm-5.3-flash-cybersecurity) glm-5.3-flash-cybersecurity | Security | $0.5093 | $1.6975 | 1049K | openai |
| [GLM-5.3 Uncensored](https://pentestllm.ai/models/glm-5.3-uncensored) glm-5.3-uncensored | Uncensored | $0.282 | $0.846 | — | openai |

Prices per million tokens, read from the live catalog on 2026-11-17.

| Model id | Daily check | Context window |
| --- | --- | --- |
| [`glm-5.3-flash-uncensored`](https://pentestllm.ai/models/glm-5.3-flash-uncensored) | Steady since Oct 12 | not published |
| [`glm-5.3-flash-cybersecurity`](https://pentestllm.ai/models/glm-5.3-flash-cybersecurity) | Steady since Oct 23 | 1,048,576 tokens |
| [`glm-5.3-uncensored`](https://pentestllm.ai/models/glm-5.3-uncensored) | Steady since Oct 12 | not published |

Context windows from the catalog of 2026-11-17; check results from /proof when the page rendered.

Default to the flash build for a channel that gets mentioned all day. For a team that mostly asks about findings, payloads under review and detection logic, set `PTL_MODEL` to the cybersecurity tune in the middle row, or to `auto/security`, which picks a security build by how hard each question is. The [red team](https://pentestllm.ai/red-team) and [CTF](https://pentestllm.ai/ctf) pages list the security builds by what they are good at.

## A month of replies, priced

Assume 300 mentions a day for 30 days. A request carries about 200 tokens (system prompt plus question) and the answer about 300.

| Model | 9,000 replies a month |
| --- | --- |
| [GLM-5.3 Flash Uncensored](https://pentestllm.ai/models/glm-5.3-flash-uncensored) | $1.18 |
| [GLM-5.3 Flash Cybersecurity](https://pentestllm.ai/models/glm-5.3-flash-cybersecurity) | $5.50 |
| [GLM-5.3 Uncensored](https://pentestllm.ai/models/glm-5.3-uncensored) | $2.79 |

Worked out at render from the catalog of 2026-11-17: replies × 200 × input rate, plus replies × 300 × output rate.

The figure moves most if you add history. Ten prior messages per request multiplies the input side by their length. `max_tokens=500` holds the output side down. The [pricing page](https://pentestllm.ai/pricing) carries every rate.

## Test the key with curl

Before you start the bot, ask the API which ids the key can reach. Free, instant.

```bash
curl https://api.pentestllm.ai/v1/models \
  -H "Authorization: Bearer sk-ptl-live-…"
```

A 200 and a list of ids: the key is good, and `PTL_MODEL` must simply be one of them. A 401 tells you how the key is wrong:

```
HTTP 401
{"error":{"message":"No API key was sent.","type":"authentication_error","param":null,"code":"invalid_api_key"}}
```

```
HTTP 401
{"error":{"message":"The API key is not valid.","type":"authentication_error","param":null,"code":"invalid_api_key"}}
```

Both bodies as the API returned them on 25 October 2026.

## When it breaks

### "The model API answered 401"

`PTL_API_KEY` is missing, mistyped or revoked. Repeat the curl above with that exact key.

### "The model API answered 404"

`PTL_MODEL` is not a catalog id:

```
HTTP 404
{"error":{"message":"No such model: glm-5.3-flash-uncensord.","type":"not_found_error","param":null,"code":"model_not_found"}}
```

### "The model API answered 402"

The balance is empty. Top up in the console. A request the API turns away for this reason costs nothing.

```
HTTP 402
{"error":{"message":"The prepaid balance does not cover this request. Top up at … to continue.","type":"insufficient_quota","param":null,"code":"insufficient_balance"}}
```

### "I only answer in the channels I am set up for"

That channel's id is not in `PTL_CHANNELS`. Copy it again with Developer Mode on. A server id or a message id pasted in its place will never match.

### PrivilegedIntentsRequired on start

The code requested an intent that is off in the Developer Portal, and Discord dropped the connection with code 4014. The file above requests none. If you add `message_content` yourself, switch it on under the Bot page too.

### Forbidden on reply

`Forbidden` is discord.py telling you a permission is missing. Confirm Send Messages and Read Message History on that channel. For other clients, the [docs page](https://pentestllm.ai/docs) has the base URL, key and model id in the same form.

## Questions

### Can I just add a hosted uncensored Discord bot?

Directories like top.gg and discord.bots.gg list hosted bots. Self-hosting, as this guide does, keeps the model choice and the per-reply cost on your own key, and keeps engagement details off someone else's server.

### How do I keep the bot out of general chat?

List only the engagement channels in PTL_CHANNELS; threads inherit their parent channel. A mention elsewhere gets a one-line notice and never reaches the API.

### Is the Message Content intent required?

No. The bot reads only messages that mention it, which Discord delivers without the intent. Requesting the intent in code while it is off in the Developer Portal makes discord.py raise PrivilegedIntentsRequired.

### Does the same design work in discord.js?

Yes. Point the OpenAI Node SDK at baseURL https://api.pentestllm.ai/v1 with your key; the flow is identical. The Node snippet is on the docs page. See the docs page.

### Which build suits a security team's Discord bot?

Any id that speaks the OpenAI wire format. A flash build keeps a busy channel cheap; a cybersecurity tune or auto/security fits a channel full of findings, CVEs and detection questions. See the model list.

### What does running an uncensored Discord bot cost?

Tokens only. The table above prices a month of replies at live catalog rates. No subscription; the balance is prepaid from $10 and never expires. See per-token prices.

Every model above is on the [uncensored model list](https://pentestllm.ai/models) with its live price per million tokens. [Per-token pricing](https://pentestllm.ai/pricing) sets the whole catalog side by side, and the [family directory](https://pentestllm.ai/uncensored) groups the builds by base model.

[Get a key](https://app.pentestllm.ai/console) Prepaid from $10, no subscription.

## New models and price changes, once a month.

New uncensored builds with their prices, price moves, and what the daily model check found.
