All-purpose know-it-all do-it-all Discord bot.
| Command | Description |
|---|---|
npm start |
Start the bot. Initializes the database connection, Discord client, and all enabled features. |
npm run deploy-commands |
Register slash commands with Discord. Requires a --destination (-d) option: all, global, or guild. |
Every feature is independently toggleable through environment variables, so the bot only runs what it's configured for.
An OpenAI-powered chatbot that hangs out in designated channels and replies to anyone who talks to it.
- Watches only the channels listed in
DISCORD_CHATBOT_CHANNEL_IDSand ignores other bots. - Builds prompts from a configurable template (
OPENAI_PROMPT) with support for{USER},{USER_MESSAGE},{CHAT_HISTORY}, and{CURRENT_DATE}placeholders. - Splits long replies into multiple messages to respect Discord's message length limit.
- Announces 🟢 online and 🔴 offline in its channels on startup and shutdown.
Self-service role assignment: members add a reaction to a message and receive the associated role, remove the reaction and lose it.
/reaction-roles add– Bind an emoji + role pair to any message./reaction-roles remove– Unbind an emoji from a message./reaction-roles nuke– Remove all reaction roles from a message.- Autocomplete suggests recently used Channel and Message IDs, so managing several bindings in a row doesn't mean re-copying IDs each time.
- Bindings persist in MongoDB and survives restarts.
- Optionally logs every change to an audit channel (
DISCORD_REACTION_ROLES_LOG_CHANNEL_ID).
Caution
The bot needs the Manage Roles and Add Reactions permissions, and any role it assigns must be placed below the bot's own role in the server's role hierarchy, otherwise the role assignment will fail.
Commands are file-based and auto-discovered: drop a file in src/discord/commands/global or src/discord/commands/guild and the deploy script picks it up. Global commands (like /about) register for every server; guild commands register only for the servers listed in DISCORD_COMMAND_GUILD_IDS.
-
Install Node.js.
-
Create a Discord application with a bot token, and grab an OpenAI API key and a MongoDB connection string for the features you plan to enable.
-
Execute
npm installto download all required dependencies. -
Copy
.env.defaultto.envand fill in the values.
Tip
Features are opt-in. Leave MONGODB_URI empty to skip the database, or set DISCORD_CHATBOT_ENABLED=0 / DISCORD_REACTION_ROLES_ENABLED=0 to switch features off without touching code.
-
Execute
npm run deploy-commands -- -d allto register slash commands with Discord. -
Execute
npm startto run the bot.
- src/main.js – Entrypoint. Loads environment variables, then initializes the database and Discord client.
- src/constants.js – Parsed environment variables and shared constants. The single source of truth for feature flags.
- src/database/ – MongoDB connection and Mongoose schemas.
- src/discord/init.js – Discord client setup and event wiring.
- src/discord/events.js – Maps Discord gateway events to feature handlers.
- src/discord/commands/ – Slash command definitions, split into
global/andguild/folders, plus the deploy script. - src/discord/handlers/ – Feature logic. Each feature owns a folder with a
handler.js(event handling) andhandler.utils.js(helpers).
- discord.js – Library for interacting with the Discord API.
- dotenv – Load environment variables from a
.envfile. - moment – Parse, validate, and format dates.
- mongoose – MongoDB object modeling.
- openai – Official OpenAI API client.
- pluralize – Pluralize and singularize words.
- yargs – Command line argument parsing.
- @trivago/prettier-plugin-sort-imports – Sort import declarations.
-
Rework the
/reaction-rolescommand structure (in progress on the feature/rework-command-structure branch):- A
selectcommand to pick a channel + message once, instead of passing IDs to every command. - Support multiple roles per reaction.
- Confirmation buttons before destructive actions.
- A
-
Persist chatbot conversation history in MongoDB so context survives restarts.
-
Migrate the chatbot from the legacy completions API to the chat completions API with a modern model.