The bot passes every test in a private server with one member, its builder. Then it joins a community of two hundred. Within the first hour someone pastes a 30,000-word crash log, someone else asks it to "say hi to @everyone", and a retrieval call that took 1.2 seconds in testing takes 4.8 under load. Discord stopped waiting at 3.0, so the user sees "The application did not respond" and the answer that arrives later has nowhere to go.

None of that is the model's fault. Discord enforces hard limits on response time, message length, edit rate and intents, and a bot that ignores them fails in a public channel in front of the people it was built for. Getting a good answer out of the model takes an afternoon. The real engineering is in the 3 seconds before that answer exists and the 2,000 characters it has to fit into.

The three-second rule

Slash commands are the right way to invoke a bot, and every one comes with a deadline. Discord gives you 3 seconds to acknowledge the interaction. Miss it and the interaction is dead: the user sees the error, and a reply that arrives after that is rejected. A cold provider, an embedding lookup plus a vector query, or a single tool call is enough to cross the line on a bad minute.

Acknowledge first and think second. Reply immediately with a deferred response (interaction callback type 5), which puts "Bot is thinking…" on screen, then run the model and PATCH the original message through the webhook endpoint when the answer is ready. That interaction token expires after 15 minutes. That's plenty for one answer and fatal for a job that waits behind a queue during a spike. If a task can run longer than that, post the result as an ordinary channel message instead of trusting the token.

Streaming without getting rate limited

Everyone wants the typing effect, so the first version edits the message on every streamed token. That's 30 to 60 PATCH requests a second against a route Discord limits to a handful every few seconds per channel. You get 429s within the first sentence. Then the bot either drops the rest of the answer or retries in a tight loop, and because the limit is shared, it starves every other command in that channel.

Buffer the stream and flush on a timer, about once a second, sending the full text so far each time. When a 429 arrives, sleep for exactly the retry_after value in the response instead of a backoff you guessed. Then handle length: a bot message caps at 2,000 characters, and a model explaining a stack trace will pass that without slowing down. Split at paragraph breaks or between code blocks. Never split inside a fence, or the second message opens with a stray ``` and everything after it renders as code.

The bot speaks with your permissions

Whatever the model writes, Discord posts it with the bot's role. If a user talks the model into writing @everyone and that role can mention everyone, every member's phone buzzes, and a moderator kicks the bot inside a minute. Send allowed_mentions with parse set to an empty list on every outgoing message, so no mention resolves unless your code adds it on purpose. It's one field, and most hobby bots leave it out.

In a shared channel, prompt injection is a group activity. Anyone can type "SYSTEM: ignore prior rules" into text that ends up in the context window. Keep your instructions in the system slot, wrap channel history as quoted user content, and never give the model a tool that bans, deletes or edits roles without a human clicking a confirm button. If the bot answers from your docs, the same discipline that keeps a RAG system from making things up applies, because a wrong answer posted confidently in #help gets screenshotted and repeated for weeks.

Memory, intents and the cost of one enthusiastic user

Reading ordinary messages, not just commands, needs the Message Content intent, and Discord treats it as privileged. Under 100 servers you flip a switch in the developer portal. Past that, verification is mandatory and Discord will only grant the intent if you can justify it, and "the bot is more convenient this way" won't pass. Build on slash commands and mentions from day one and you won't be rewriting the input layer at the worst possible moment.

Use threads as memory. Open one thread per conversation, rebuild context from that thread's history on each message, and cap the read at something like the last 20 messages. A billing question in #support then never leaks into a roadmap argument in #general, and starting fresh is just opening a new thread. Once a thread runs long, store a rolling summary and send that plus the recent turns, not 300 messages of history on every call.

Then cap each user's cost. The first member who finds the bot will co-write a novel with it at your expense. Set per-user and per-server rate limits, cut off input at a fixed length so the 30,000-word log gets refused instead of tokenised, and give each server a daily token budget that ends with a clear message rather than silence. Log every exchange with user, server and token count, so the bill has names on it. Before launch, run a script of hostile and ordinary messages against the bot, as we cover in how to test code that calls an LLM.

Build it or buy one

Off-the-shelf AI bots are fine for banter in a casual server. They stop being enough when the bot has to answer from your product docs, respect your role hierarchy, call your backend, or behave in a way you can defend to your moderators. Our comparison of custom chatbots against SaaS tools applies here almost word for word. The deciding question is who carries the blame when the bot is wrong in public.

If you go custom, the build has four parts: a gateway connection that heartbeats and resumes through resume_gateway_url instead of re-identifying after every drop, an interaction handler that defers within milliseconds, a model layer with retrieval and budgets, and an output layer that throttles edits, splits at safe boundaries and strips mentions. None of it is exotic, and leaving out any one part is how the bot gets kicked. That's the AI chatbot development we do: dull to describe, and quiet once it's running.

Questions, answered.

Why does my Discord bot say the application did not respond?

Discord kills any interaction that isn't acknowledged within 3 seconds. Send a deferred response (callback type 5) immediately, run the model, then edit the original message. The token stays valid for 15 minutes.

How do I stream AI responses in Discord without hitting rate limits?

Buffer the model's output and edit the message about once a second instead of on every token. On a 429, wait exactly the retry_after value. Split answers over 2,000 characters at paragraph or code-block boundaries, never inside a fence.

Does an AI Discord bot need the Message Content intent?

Only if it reads ordinary messages. Slash commands and mentions work without it. The intent is privileged: you can toggle it freely under 100 servers, but past that, verification is required and Discord must approve it.

How do I give a Discord AI bot memory?

Use one thread per conversation and rebuild context from that thread's recent history, capped at around the last 20 messages. For long threads, store a rolling summary and send it with the latest turns instead of the full history.

How do I stop an AI Discord bot from pinging everyone?

Send allowed_mentions with an empty parse list on every message, so no mention resolves unless your code adds it deliberately. The prompt alone won't stop it, because users in a shared channel can talk the model into writing anything.