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-tokenCopied from the Bot page in the Developer Portal
- PTL_API_KEY
- sk-ptl-live-…Made in the console; displayed one time
- PTL_CHANNELS
- 123456789012345678Ids of the channels it may answer in, separated by commas
- PTL_MODEL
- glm-5.3-flash-uncensoredOptional; 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.
- Open the Developer Portal, give the new app a name and press Create.
- Go to the Bot page. Under Token, press Reset Token and paste the result into
DISCORD_TOKEN. You get one look at it. - Go to the Installation page and select the Discord Provided Link. Under Default Install Settings, add the
botscope to Guild Install. - 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.
- Follow the install link, press Add to server, and confirm the bot has visibility into every channel it should serve.
- 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: a security team's channel bot. Answers @mentions in the listed channels with an uncensored model.import osimport re import discordfrom 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.eventasync def on_ready(): print(f"Logged in as {client.user}") @client.eventasync 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
python3 -m pip install discord.py openaiexport DISCORD_TOKEN="your-bot-token"export PTL_API_KEY="sk-ptl-live-…"export PTL_CHANNELS="123456789012345678" # channel ids, comma-separatedexport PTL_MODEL="glm-5.3-flash-uncensored" # optionalpython3 bot.pyWhen 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:
| Wire formats | |||||
|---|---|---|---|---|---|
| GLM-5.3 Flash Uncensored | Uncensored | $0.1053 | $0.3685 | — | |
| GLM-5.3 Flash Cybersecurity | Security | $0.5093 | $1.6975 | 1049K | |
| GLM-5.3 Uncensored | Uncensored | $0.282 | $0.846 | — |
| Model id | Daily check | Context window |
|---|---|---|
glm-5.3-flash-uncensored | Steady since Oct 12 | not published |
glm-5.3-flash-cybersecurity | Steady since Oct 23 | 1,048,576 tokens |
glm-5.3-uncensored | Steady since Oct 12 | not published |
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.
| Model | 9,000 replies a month |
|---|---|
| GLM-5.3 Flash Uncensored | $1.18 |
| GLM-5.3 Flash Cybersecurity | $5.50 |
| GLM-5.3 Uncensored | $2.79 |
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 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"}}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 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.