Before you start
You need a project checkout, Node.js 22 or newer, a Discord account, and a database. A local model also needs Ollama and enough memory to run it. Hosted model providers can be used instead, but they receive the questions and evidence used for replies.
Clone ThreadSherpa.Get the code from the public GitHub repository. The bot uses Node.js 22 or newer; building this website needs Node.js 22.23.4 or newer.
Use a dedicated test server first. Do not import another community's messages, screenshots, or policies as a knowledge base. The bot reads new events in channels you connect; it does not backfill historical posts.
1. Create the Discord bot
- Open theDiscord Developer Portaland create an application. Name it ThreadSherpa.
- Open Bot, reset or copy the bot token, and keep it private. The token goes in
DISCORD_BOT_TOKEN. A reset invalidates the previous token. - On the Bot page, enable Message Content Intent. ThreadSherpa does not request Server Members Intent or Presence Intent.
- Open Installation and enable Guild Install. Invite the bot with the
botandapplications.commandsscopes. It does not need Administrator.
The bot needs View Channels, Read Message History, Send Messages, Send Messages in Threads (or Send Messages in Posts), and Embed Links in the support channel. Thread permissions are inherited from the parent forum, but channel overrides can still block it.
Reference:Discord's bot setup guideandDiscord permissions.
2. Choose storage and a model
MongoDB
Create a free MongoDB Atlas cluster, a database user, and a network access entry for the machine running the bot. Copy the driver connection string. It looks likemongodb+srv://… and includes the database user and password. Password characters reserved in URLs must be percent-encoded.
- MongoDB Atlas
- Create a free cluster
- Add a database user
- Add an IP access entry
- Get the driver connection string
Local inference with Ollama
Install Ollamaand pull the reply model and embedding model named in the project's environment template. Keep Ollama running while the bot is running. Local inference keeps the synthesis request on your machine; Discord and the database still use the network.
Paper Instruments
Paper is optional. It uses server-side API credit for synthesis, while local embeddings still run through Ollama. Add its key only on the machine running the bot. Do not put a provider key in browser code, a screenshot, or a commit.
3. Configure the environment
Create .env from the project's .env.example. Keep it out of version control. These are the variable names you will see; values are yours and should never be posted publicly.
| Variable | Purpose |
|---|---|
DISCORD_BOT_TOKEN | The bot token from the Discord Developer Portal. |
MONGODB_URI | The Atlas driver connection string. |
MONGODB_DB_NAME | Optional database name. The default is threadsherpa. |
MODEL_PROVIDER | ollama or paper. |
PAPER_INSTRUMENTS_API_KEY | Only for Paper mode. Optional otherwise. |
DISCORD_DEV_GUILD_ID | Optional test-server ID for immediate command registration. |
The project's setup checker creates .env only when it does not exist. It never overwrites existing keys. It checks access without posting Discord messages or requesting paid generation.
4. Check the configuration and start
npm ci
npm run setup
npm run devRun the checker after each configuration change. You want Discord, MongoDB, and the chosen models to report OK. The checker prints a ready-to-use invite URL when the Discord token works. Open it, choose your test server, and authorize the bot. For a production process, use npm run build then npm start.
5. Connect the support forum
A forum's top-level view has no normal message composer, so do not run setup there. Run the command from a regular text channel, such as #bot-commands, as a server administrator:
/setup channel:#your-forum autonomy_mode:autoSelect your actual support forum in the command's channel option. This works before the forum has any posts, and you do not repeat it for every question. Commands run in the text channel; the bot connects the selected forum.
If you already have a forum post, you can alternatively run/setup autonomy_mode:auto inside that post on first setup; the bot selects its parent forum. For an ordinary text support channel, run/setup autonomy_mode:auto directly in it, or select it with thechannel option.
Automatic replies apply to new posts in the selected forum. Unknown questions wait quietly in /queue. To stop monitoring a forum, run/setup remove_channel:#your-forum from a regular text channel.
6. Save the first answer
- Create a synthetic question in a support post.
- Reply as a moderator, then right-click your answer, open Apps, and choose Save this answer. You will see Saved. orAlready saved.
- Ask a new question in different words. When the saved facts support it, ThreadSherpa writes a short reply and links the original answer.
- Check
/queuefor questions that were not answered. Use/answersto edit or remove saved guidance, and/teachwhen there is no existing answer message to save.
A clear “that worked” confirmation closes a case without another bot message. A “that didn't work” reply queues the attempted advice for review. Saving knowledge does not post into older questions.
If something blocks you
| What you see | What to check |
|---|---|
| Discord token rejected | Use the Bot Token, not the client secret or application ID. If you reset it, update .env. |
| Bot cannot read posts | Enable Message Content Intent on the Bot page, then restart the bot. |
| MongoDB cannot connect | Check the database user, password encoding, and the current IP entry in Atlas. |
| Slash commands are missing | Invite the bot with the URL from the checker and restart it. For multiple servers, set DISCORD_DEV_GUILD_ID for immediate test-server registration. |
| No reply in a forum post | Run /setup channel:#your-forum autonomy_mode:auto from a text channel. Unknown questions are intentionally quiet; check /queue and the forum permissions. |
| Ollama is missing | Open Ollama, pull the models named in the environment template, and run the checker again. |
Read the security boundaries before using real community data. For operational limits and data handling, the project's security notes are the authority.