← Blog

Discord AI Agent: Self-Hosted Setup With POLYROB

Discord AI Agent: Self-Hosted Setup With POLYROB

A Discord AI agent is an AI assistant you talk to in Discord, in a DM or in a server channel. It acts for you: it uses tools, keeps memory and answers in the same chat. POLYROB runs one on your own machine. The command polyrob discord connects to Discord’s gateway websocket as a bot, so it needs no public URL, no webhook and no open port.

Most guides on this topic show how to wire a hosted bot builder into a server. This one covers the other case: your own agent, on your own hardware, that you reach from Discord. Every POLYROB claim comes from the public repository at release v1.7.9, and the files are listed at the end.

What is a Discord AI agent?

A bot relays a message to a model and posts the text back. An agent also does work: it browses, reads and writes files, runs scheduled jobs and remembers you between sessions. In POLYROB, Discord is one way to reach the same agent. It answers in the terminal, the web console and eight chat apps, and it keeps one memory across them. For the wider picture of running an agent yourself, read the guide to a self-hosted AI agent.

How does POLYROB connect to Discord?

Through the Discord gateway, a websocket your machine opens to Discord (Discord, Gateway documentation). Because your machine makes the call, nothing has to reach it from outside. That is the main difference from WhatsApp, where Meta calls a public webhook.

The gateway code is a small hand-written client:

What do you need before you start?

A bot token and a model. There is no extra to install: the Discord surface has no optional dependency group in the surface catalog. Create the application in the Discord developer portal (Discord developer applications), add a bot, and turn on the MESSAGE CONTENT privileged intent. Then invite the bot to your server with the bot scope.

SettingWhat it does
DISCORD_BOT_TOKENThe bot token. You can pass --token instead; the option wins over the variable.
OWNER_DISCORD_IDYour numeric Discord user ID. A sender whose ID equals it is the owner on Discord.
GROUP_CHAT_ENABLEDOff by default. Needed before the bot answers in a server channel.

How do you start it?

Install POLYROB, export the token and run the command.

curl -fsSL https://polyrob.dev/install.sh | bash
export DISCORD_BOT_TOKEN=your-bot-token
polyrob discord

It prints discord bot online, then listening. If the token is missing, the command stops with one message that names --token and DISCORD_BOT_TOKEN. To check a token without starting the agent, run polyrob surfaces probe discord. It reads the bot’s own profile and its application flags, and it tells you if the MESSAGE CONTENT intent is off. Without that intent, Discord closes the gateway with code 4014 on every connect.

If you run several chat apps, polyrob gateway starts every enabled surface in one process. Discord is skipped with a warning when the token is missing.

Who can talk to it?

Only you, until you say otherwise. On every network surface except Telegram, a DM from anyone who is not the owner or a paired sender is denied, even when the correspondent model is off. Set OWNER_DISCORD_ID to your user ID so your messages count as the owner’s.

The bot also ignores other bots, and it ignores its own messages. It posts with mention parsing turned off, so a reply that contains @everyone or a role name does not ping anyone. The AI agent security guide explains the access model behind this.

Can you use it in a server channel?

Yes, once you opt in twice. Turn on GROUP_CHAT_ENABLED, then allow each channel by ID:

polyrob config set GROUP_CHAT_ENABLED true
polyrob owner groups allow discord 123456789012345678

The start-up line then reads group chat ON, and only allowlisted channels respond. An unlisted channel is dropped silently: nothing is stored and nothing is sent. Inside an allowed channel the bot answers when it is mentioned, by default. Each sender has a role (owner, admin, member or blocked), and a room turn runs on a narrower toolset than a DM, with no owner facts, no wallet and no memory recall. The groups guide is the full reference.

What does it do in the chat?

Where does the Discord surface fall short?

Can the same agent run in other chat apps?

Yes. POLYROB has eight chat surfaces: Telegram, email, WhatsApp, Discord, Slack, Signal, Feishu/Lark and DingTalk. The Telegram AI agent guide covers the phone-first case with a full room history, and the Slack AI agent guide covers the workplace case. For the owner-chat-plus-goals setup, see the personal AI agent guide. If channel count decides it for you, check the dated numbers on the comparison page.

Discord AI agent questions

How do I create an AI agent for Discord?

Create an application and a bot in the Discord developer portal, turn on the MESSAGE CONTENT intent, and invite the bot. Then set DISCORD_BOT_TOKEN, set OWNER_DISCORD_ID to your user ID, and run polyrob discord.

How do I contact a Discord agent?

Send the bot a DM. If you are the owner, the DM is your private chat with the agent. In a server, mention the bot in a channel you have allowed with polyrob owner groups allow discord <channel_id>.

Do I need a public URL?

No. The gateway is a websocket that your machine opens, so it works behind a home router or a firewall.

What is the best bot for Discord management?

That depends on what you manage. POLYROB is an agent you talk to, not a moderation tool: its Discord client has no ban, kick or role calls. Use a moderation bot for that job, and POLYROB for work you would ask an assistant to do.

Is it free?

POLYROB is MIT licensed. You pay your model provider, or nothing with a local model. Discord sets its own rules for bots, so read them before you plan around volume.

Where do you start?

Create the bot, run the three commands above, and send it a DM. Then allow one channel if you want it in a server.

Install POLYROB, read the docs, or browse the open-source code. To see what changed in recent releases, check what’s new.

Sources

All POLYROB facts are from the public repository at release v1.7.9 (github.com/theselfruleorg/polyrob).


POLYROB is an open-source AI agent you run and own. Install it or read the docs.