Skip to main content
← Journal·AI AutomationsOctober 7, 2026·10 min read

Build an AI Discord Bot That Answers From Your Own Docs

Build an AI Discord bot that answers questions from your own docs: slash commands, a hosted vector store, per-channel access and cost per 1,000 questions.

A

Founder of IImagined.ai

Quick answer

An AI Discord bot that answers from your own docs needs four parts: a Discord app with an /ask slash command, a hosted vector store holding your documents, a model call with a retrieval tool, and an access map that decides which documents each channel may search. On published OpenAI rates, 1,000 questions cost a few dollars in this illustrative setup.

To build an AI Discord bot that answers questions from your own docs, register an /ask slash command, store your documents in a hosted vector store, and answer each question with a model call that searches only the documents that channel is allowed to see. Defer the reply first, because Discord expects a response within 3 seconds, then edit in the answer with its sources.

Checked October 2026 against Discord's developer docs on receiving and responding to interactions, privileged intents and messages, plus OpenAI's file search guide and API pricing.

Most "AI Discord bot maker" tools give you a general chatbot with a personality. That is not what a community or product team needs. You want a bot that answers the same twenty questions your moderators answer every day, from your actual docs, and says "I don't know" when the docs do not cover it. This tutorial builds that, with per-channel permissions and a cost per 1,000 questions worked out from published rates. It sits in our business chatbots hub, starting with the WhatsApp Business API guide, which covers the same pattern on another channel.

What your AI Discord bot will do at the end

  • An /ask command that answers from your FAQs, guides and policies, with the source file named.
  • An access map: public docs in every channel, internal docs only in staff channels.
  • A clear refusal when the docs do not cover a question, instead of a made-up answer.
  • A cost estimate you can rerun with your own volumes.
How the bot answers a question
  1. 01
    /ask in a channel

    Member types a question

  2. 02
    Bot defers the reply

    Within 3 seconds

  3. 03
    Access map

    Channel and roles pick the allowed document stores

  4. 04
    Model + file search

    Retrieves matching chunks, writes the answer

  5. 05
    Edited reply

    Answer plus source names, or a clear refusal

Prerequisites

Pre-flight checklist
  • A Discord server where you have Manage Server permission
  • A Discord developer account and a new application in the Developer Portal
  • An OpenAI API key with billing enabled (see our API key guide)
  • Your documents as PDF, Markdown, text or DOCX files, reviewed and current
  • Node.js (or Python) and an always-on host for the bot process
  • A list of which channels may see which documents

If you have not created an API key before, our guide to getting an OpenAI API key covers billing limits and keeping the key out of your code. The same architecture works with other model providers; the retrieval step is the part you would swap.

Build the Discord AI chatbot, step by step

From empty app to working /ask
  1. 1
    Create the app and bot

    Developer Portal, New Application, then add a bot and copy its token into an environment variable. Expected result: an offline bot user.

  2. 2
    Invite it with the right scopes

    Generate an invite URL with bot and applications.commands. Grant only View Channel and Send Messages. Expected result: the bot appears in your member list.

  3. 3
    Register the /ask command

    One string option, question, required. Register it on your test server first so it shows up immediately.

  4. 4
    Create a vector store and upload docs

    One store per access tier, for example public and staff. Expected result: files show as completed in the store.

  5. 5
    Write the access map

    Channel IDs and role IDs to allowed store IDs, kept in config, not in the prompt.

  6. 6
    Handle the interaction

    Defer, look up allowed stores, call the model with file search, edit the reply.

  7. 7
    Lock down command permissions

    In Server Settings, Integrations, limit where /ask can be used.

The interaction handler

Here is the core of the handler as a sketch. It assumes discord.js and OpenAI's Node SDK; storesFor is your own function that reads the access map.

// Sketch only: discord.js + OpenAI Responses API with file search
client.on('interactionCreate', async (interaction) => {
  if (!interaction.isChatInputCommand() || interaction.commandName !== 'ask') return
  await interaction.deferReply()                       // beat the 3-second limit
  const stores = storesFor(interaction.channelId, interaction.member)  // your access map
  if (stores.length === 0) return interaction.editReply('Not available in this channel.')
  const res = await openai.responses.create({
    model: 'gpt-5.4-mini',
    instructions: 'Answer only from the provided files. If they do not cover it, say so.',
    input: interaction.options.getString('question', true),
    tools: [{ type: 'file_search', vector_store_ids: stores }],
  })
  await interaction.editReply(res.output_text.slice(0, 2000))   // Discord message limit
})

Three details in that sketch matter. The deferral comes first, because Discord's interaction docs require an initial response within 3 seconds; the token then stays valid for 15 minutes for edits and follow-ups. The instructions tell the model to stay inside the files. And the reply is trimmed to Discord's 2,000-character message limit, or split across follow-ups for longer answers.

Making a Discord bot that answers questions well

Retrieval quality decides whether members trust the bot. OpenAI's file search tool runs semantic and keyword search over files in a vector store and supports metadata filtering, so you can tag files with attributes such as product, version or audience and filter at query time instead of creating a store per combination.

  • Curate before you upload. One accurate FAQ beats a hundred old threads. Remove outdated pages; the bot will happily quote them.
  • Write answer-shaped docs. A heading per question with the answer underneath retrieves better than long narrative pages.
  • Show sources. Name the file each answer came from so members and moderators can check it.
  • Allow "I don't know". Tell the model to say when the files do not cover a question and to point to a human channel.
  • Log questions with no good answer. They are your list of docs to write next.

If you want to understand retrieval itself rather than use a hosted tool, our overview of an all-in-one RAG platform explains chunking, embeddings and search in plain terms.

Do you need the Message Content intent?

For an /ask bot, no. Message Content is a privileged intent: without it, the content, embeds, attachments and components fields of messages arrive empty, per Discord's message docs. Slash command options come through the interaction itself, and Discord's docs note that apps still receive content in DMs and in messages that directly mention the bot. You need the intent only to read ordinary channel messages, for example to index server history or to answer unprompted.

Discord changed how access works: the privileged intent review threshold is now based on unique users who can see your app rather than server count. Above 10,000 users you must apply, and approved apps reapply annually (checked October 2026). Building on slash commands from the start avoids that review entirely.

Cost per 1,000 questions: an illustrative calculation

Illustrative math from OpenAI's published standard rates, checked October 2026, not a measurement. Inputs: one file search call per question, about 6,000 input tokens per question (instructions, retrieved chunks and the question; OpenAI bills tokens used by built-in tools at the model's rates) and about 400 output tokens. Prices: file search tool calls at $2.50 per 1,000; gpt-5.4-mini at $0.75 per million input and $4.50 per million output tokens; gpt-5-mini at $0.25 and $2.00.

LineIllustrative volumegpt-5.4-minigpt-5-mini
File search tool calls1,000 calls x $2.50 per 1k$2.50$2.50
Input tokens6M tokens (6,000 per question)$4.50 at $0.75/1M$1.50 at $0.25/1M
Output tokens0.4M tokens (400 per question)$1.80 at $4.50/1M$0.80 at $2.00/1M
Vector storageUnder 1 GB of docs$0 (first GB free)$0 (first GB free)
Total per 1,000 questions$8.80$4.80

Under a cent a question in both cases, on these inputs. Two levers move it most: the size of retrieved context (fewer, better chunks cut input tokens) and the model. On the smaller model, the file search fee becomes the biggest line, which is when running your own embeddings (text-embedding-3-small is $0.02 per million tokens) and your own vector database starts to make sense, at the price of hosting it. Storage stays free for most servers, since the first GB is free and $0.10 per GB per day after that. For other providers' token prices, see our LLM API pricing comparison.

Running the bot in production

A bot that works on your test server still needs a few habits before a busy community relies on it. None of them are complicated, but skipping them is how bots end up switched off a month after launch.

  • Keep the docs fresh. Re-upload a file whenever the source page changes, and delete the old version from the vector store so the bot cannot quote both. A weekly review of the "no good answer" log tells you which pages to write or fix.
  • Set a per-member limit. A simple cooldown per user per minute stops one person, or one script, from running up your bill. Pair it with a monthly spend limit on the API account.
  • Keep secrets out of the repo. The bot token and API key belong in environment variables on the host. If a token leaks, reset it in the Developer Portal at once.
  • Tell members what it is. Pin a short note in each channel where /ask works: what the bot can answer, that answers come from your docs, and where to reach a human moderator.
  • Watch the first week closely. Read every answer for the first few days. Wrong answers usually point to a missing or outdated document rather than a model problem.

Hosting is the cheap part. The bot is one long-running process with a gateway connection, so any small always-on server or container works. If you already self-host automation tools, it can run next to them; restart it automatically if it crashes, and log errors without logging member messages or tokens.

Troubleshooting

SymptomLikely causeFix
"The application did not respond"No response within 3 secondsDefer the reply first, then edit it
Slash command does not appearMissing applications.commands scope, or global commands still propagatingRe-invite with the scope; register guild commands while testing
Bot reads empty message textMessage Content intent not enabledUse slash commands or mentions, or enable the intent
Confident wrong answersRetrieval found nothing relevantTell the model to say it does not know; show sources
Staff docs leak into public answersAll channels search the same storeMap channels to stores before retrieval

Building the same thing for another chat app? Our Telegram bot tutorial covers the bot setup side on Telegram, and the retrieval half of this guide carries over unchanged. If you want to turn bots like this into a product you sell to communities or clients, our AI SaaS Builder program covers scoping, pricing and shipping it.

AI Discord bot: FAQ

How do I make an AI Discord bot that answers questions?

Create an application in the Discord Developer Portal, add a bot user and invite it with the applications.commands scope. Register an /ask slash command. When someone uses it, defer the reply, send the question to a language model with a retrieval tool pointed at your documents, and edit the deferred reply with the answer and its sources. Host the bot on any always-on server or container.

Does a Discord AI chatbot need the Message Content intent?

Not if it answers through slash commands, mentions or DMs. Discord's docs say apps still receive message content in DMs and in messages that directly mention the bot, and slash command options arrive in the interaction itself. You need the privileged Message Content intent only to read general channel messages, for example to index server history, and apps visible to more than 10,000 users must apply for it.

How much does it cost to run an AI Discord bot?

Mostly model and retrieval usage. On OpenAI's published rates (checked October 2026), file search costs $2.50 per 1,000 tool calls plus model tokens. In our illustrative example, 1,000 questions on gpt-5.4-mini come to about $8.80, or about $4.80 on gpt-5-mini. Vector storage is $0.10 per GB per day after the first free GB. Hosting the bot process adds a small fixed cost.

Can the bot give different answers in different channels?

Yes, and it should. Map each channel or role to the document sets it may search, for example public docs everywhere and internal runbooks only in a staff channel. Check the channel ID and the member's roles before retrieval, then pass only the allowed vector store IDs or attribute filters. Combine this with Discord's own command permissions so the command is hidden where it should not be used.

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

Discord requires an initial response to an interaction within 3 seconds, or the interaction token is invalidated. Retrieval and model calls usually take longer, so defer the reply first, which shows a thinking state, then edit it when the answer is ready. The interaction token stays valid for 15 minutes for follow-up messages, which leaves plenty of room for a slow model call.

Should I index my whole Discord server history?

Usually not at first. Start with curated documents such as FAQs, guides and pinned answers, which are accurate and safe to quote. Server history is noisy, includes outdated answers and personal messages, and needs the Message Content intent to read. If you do index history, limit it to public help channels, tell members, honour deletions and follow Discord's developer terms.

All Access · all four programs · $99/mo

Building bots for communities? Learn the whole automation stack.

All Access includes the AI SaaS Builder program alongside the other three programs, live coaching and the private community, so you can plan, price and ship automation products in one place.

Start All Access — $99/mo →30-day money-back guarantee
Free · no signup

See a working community up close

Join the free Discord to ask questions, share your bot builds and see what other builders are shipping.

About the author

Written by Anyro, Founder of IImagined.ai. IImagined.ai is a founder-led education platform teaching Instagram growth, AI influencers, digital products, and AI automation.

Results vary; no income is guaranteed.

All-Access subscription

Every program. Member benefits.
One subscription.

Use all four premium programs with weekly live coaching, a private community, and the resource vault.

Confirm current lessons, downloadable resources and member-benefit arrangements before purchasing.

  • All 4 premium programs plus free Futures Trading
  • Weekly live coaching calls
  • Private community access
  • Resource vault and templates
  • 30-day money-back guarantee, cancel anytime
$99/ month
$99 for the first month · $702 to buy all four standalone
Start All-AccessOr browse standalone programs
30-day money-back guarantee · $99/month · cancel anytime