Skip to content

Repository files navigation

🤖 Rambler

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.

Features

Every feature is independently toggleable through environment variables, so the bot only runs what it's configured for.

Chatbot

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_IDS and 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.

Reaction roles

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.

Slash commands

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.

Getting started

Environment setup

  1. Install Node.js.

  2. 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.

Development workflow

  1. Execute npm install to download all required dependencies.

  2. Copy .env.default to .env and 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.

  1. Execute npm run deploy-commands -- -d all to register slash commands with Discord.

  2. Execute npm start to run the bot.

Project structure

  • 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/ and guild/ folders, plus the deploy script.
  • src/discord/handlers/ – Feature logic. Each feature owns a folder with a handler.js (event handling) and handler.utils.js (helpers).

Dependencies

Libraries & Tools

  • discord.js – Library for interacting with the Discord API.
  • dotenv – Load environment variables from a .env file.
  • 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.

Prettier plugins

Roadmap

  • Rework the /reaction-roles command structure (in progress on the feature/rework-command-structure branch):

    • A select command to pick a channel + message once, instead of passing IDs to every command.
    • Support multiple roles per reaction.
    • Confirmation buttons before destructive actions.
  • 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.

About

All-purpose know-it-all do-it-all Discord bot.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages