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 or what abliteration is 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. 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 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, 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 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.

bot.py
1# bot.py: a security team's channel bot. Answers @mentions in the listed channels with an uncensored model.
2import os
3import re
4
5import discord
6from openai import APIStatusError, AsyncOpenAI
7
8MODEL = os.environ.get("PTL_MODEL", "glm-5.3-flash-uncensored")
9SYSTEM = (
10 "You are a terse, technical assistant on a security team's Discord server. "
11 "The team works on authorized engagements. Answer in plain text, under 1,500 characters."
12)
13
14CHANNELS = {int(c) for c in os.environ.get("PTL_CHANNELS", "").split(",") if c.strip()}
15
16llm = AsyncOpenAI(base_url="https://api.pentestllm.ai/v1", api_key=os.environ["PTL_API_KEY"])
17client = discord.Client(intents=discord.Intents.default())
18
19
20def listed(channel) -> bool:
21 # A thread counts as its parent channel. DMs are never listed, so the bot stays quiet there.
22 return channel.id in CHANNELS or getattr(channel, "parent_id", None) in CHANNELS
23
24
25@client.event
26async def on_ready():
27 print(f"Logged in as {client.user}")
28
29
30@client.event
31async def on_message(message: discord.Message):
32 if message.author.bot or client.user not in message.mentions:
33 return
34 if not listed(message.channel):
35 await message.reply("I only answer in the channels I am set up for.")
36 return
37 prompt = re.sub(rf"<@!?{client.user.id}>", "", message.content).strip()
38 if not prompt:
39 return
40 try:
41 async with message.channel.typing():
42 reply = await llm.chat.completions.create(
43 model=MODEL,
44 messages=[
45 {"role": "system", "content": SYSTEM},
46 {"role": "user", "content": prompt},
47 ],
48 max_tokens=500,
49 )
50 except APIStatusError as err:
51 await message.reply(f"The model API answered {err.status_code}.")
52 return
53 text = reply.choices[0].message.content or "(empty reply)"
54 await message.reply(text[:2000])
55
56
57client.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

shell
1python3 -m pip install discord.py openai
2export DISCORD_TOKEN="your-bot-token"
3export PTL_API_KEY="sk-ptl-live-…"
4export PTL_CHANNELS="123456789012345678" # channel ids, comma-separated
5export PTL_MODEL="glm-5.3-flash-uncensored" # optional
6python3 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 (effective 29 September 2025, read on 25 October 2026) govern what the bot posts, and its 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: 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, a fixed prompt sent to every model once a day:

Uncensored models and their prices per million tokens
Wire formats
GLM-5.3 Flash Uncensoredglm-5.3-flash-uncensoredUncensored$0.1053$0.3685—openai
GLM-5.3 Flash Cybersecurityglm-5.3-flash-cybersecuritySecurity$0.5093$1.69751049Kopenai
GLM-5.3 Uncensoredglm-5.3-uncensoredUncensored$0.282$0.846—openai

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

Model idDaily checkContext window
glm-5.3-flash-uncensoredSteady since Oct 12not published
glm-5.3-flash-cybersecuritySteady since Oct 231,048,576 tokens
glm-5.3-uncensoredSteady since Oct 12not 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 and 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.

Model9,000 replies a month
GLM-5.3 Flash Uncensored$1.18
GLM-5.3 Flash Cybersecurity$5.50
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 carries every rate.

Test the key with curl

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

curl
1curl https://api.pentestllm.ai/v1/models \
2 -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
1HTTP 401
2{"error":{"message":"No API key was sent.","type":"authentication_error","param":null,"code":"invalid_api_key"}}
http
1HTTP 401
2{"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
1HTTP 404
2{"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
1HTTP 402
2{"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 has the base URL, key and model id in the same form.

Questions

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.

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.

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.

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.

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.

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 with its live price per million tokens. Per-token pricing sets the whole catalog side by side, and the family directory groups the builds by base model.

Get a keyPrepaid 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.

Help