Case Study/Discord/Design, engineering, maintenance
500-Command Discord Suite
- Author
- Aryan
- Client
- Open source
- Published
- 2024
- Length
- 6 min · 1267 words
Abstract
500+ command Discord bot with per-server MongoDB settings and one file per command.
Key outcomes
- Commands
- 500+
- Forks
- 410+
- Stars
- 275

Five hundred commands is a distribution problem
A Discord bot that stays small is easy to write and easy to grow. The failure mode is consistent across the ecosystem: the command list starts as a switch statement, becomes a chain of conditionals guarding prefixes and arguments, and ends as one file nobody wants to open. Adding the five hundredth command is hard because of where the command has to be added, and the command itself is the routine part of the job.
This bot is built around that observation. Every command is a module in its own file, files are grouped into directories by category, and registration is a directory walk at boot rather than a hand-maintained list.
Folder-per-category registration
The layout is the contract. src/bot.js is an entry point and nothing else. A command lives at src/commands/ under a category directory, one file per command. The categories in the repository include afk, announcement, automod, autosetup, birthdays, bot, casino, config, custom-commands, developers, economy, family, fun, games, giveaway, guild and images.
The loader walks those directories, reads each module’s exported metadata, and builds the dispatch table in memory. The consequences are specific and worth stating. Adding a category means adding a directory. Adding a command means adding a file. Removing a broken command means deleting a file and restarting. No central file changes, so two people adding unrelated features never collide in the same place, which matters far more on a repository with hundreds of forks than it does on a private one.
Shared helpers sit in src/assets/utils: a trivia player with its own state machine, a duration formatter, and static data tables. Keeping those out of command files is what stops the economy and casino categories from each reimplementing the same formatting and the same random helpers.
Per-guild state in MongoDB
A bot in one server can keep its settings in memory. A bot in thousands cannot, and the failure mode of getting this wrong is quiet. One guild’s configuration changes another guild’s behaviour, usually in the least reproducible way available, and the bug report names the symptom rather than the setting.
Settings are therefore stored per guild and read through a single access path, rather than assembled from conditions inside each command. Prefixes, enabled modules, welcome and leave messages, log channels, level messages, ticket messages, verify roles and embed colours are all guild-scoped records. The project also carries a small JSON file from its earlier state, and that residue is a useful marker of where the boundary is: a JSON store is adequate while the bot is one process writing one file, and it was replaced by a database precisely when multi-tenant requirements made a single shared file the wrong shape.
Configuration is self-serve, and that is a design constraint
The bot’s surface is not only for members. The config and autosetup categories exist so a server owner can set up welcome messages, log channels, ticket panels, voices, fun and games without contacting the author. That is an operational decision wearing a feature’s clothes. A bot with hundreds of forks and thousands of installs cannot be supported by hand, and every setting that requires a maintainer to change is a support request. Enough of them turn maintenance into a job.
Making setup self-serve also constrains the data model in a way that helps. Anything configurable has to have a default, a validator and a place to be rendered, which pushes configuration out of code and into records. The result is that the bot’s behaviour is largely describable from its database rather than from its source.
The categories that carry the most state
Economy and casino form a small system, and the player state they share is what makes the two categories one mechanism. Balances, items, daily and hourly claims, working, robbery, deposits and leaderboards all mutate shared player state, and every one of them has to be safe when a member runs two commands in the same second. Giveaways carry time: start, pause, unpause, edit, end, reroll and drop each need a scheduled component and a persistent record, so a restart does not cancel an entry. Birthdays are the same problem on a much longer clock.
This is where the modular structure earns its keep. A category’s state model, its commands and its schedulers can be reasoned about together, without reading the other four hundred commands to find out what else touches the same collection.
What breaks at this size
Three things, and none of them were visible when the bot was small.
Startup cost. A directory walk over hundreds of modules is not free, and it runs on every restart. It is small in absolute terms, but it is the difference between a bot that restarts in a moment and one that does not, and it is why the loader reads metadata rather than executing full command bodies eagerly wherever it can avoid it.
Permission and context checks. At a hundred commands it is tempting to check permissions inside each command. At five hundred, the checks that get forgotten are the ones that matter. Moving the common guards, guild-only, owner-only and argument validity, into the dispatch path rather than the command body is the correct fix, but retrofitting it means revisiting commands individually, and that is a long tail with no satisfying end.
Duplicate and near-duplicate commands. Categories grow independently, so a server-info style command appears in more than one place with slightly different arguments. At this size that is a coherence problem rather than a code problem, and it is answered by review rather than by structure.
What it taught, and what later bots reuse
This is the codebase where multi-tenant state became a reflex rather than an afterthought, and where the command-category handler that later bots reuse was worked out. The pattern is unremarkable now: one folder per category, one file per command, guild-scoped records, a self-serve configuration surface. At the time each of those was a decision made against the obvious alternative of a single growing script.
The clearest lesson is about ratio. The repository began as a working bot and was extended, so a large part of the engineering was reading an existing structure closely enough to extend it without breaking the conventions already in it. That situation is more common in practice than greenfield work, and the discipline it demands, change the smallest thing that fits the existing shape and document the convention rather than silently replacing it, is what kept a five-hundred-command surface coherent enough that other people could still fork it.
What I would do differently
Registration, dispatch and the configuration surface are the three parts I would re-cut.
The loader is per-command, and at this size it should be per-category with an index. Loading a whole category’s metadata at once makes category-level enablement, cooldowns and guards natural instead of special-cased, and it removes the duplicate-guard problem at the root rather than policing it by review.
The JSON-to-database transition left a residue of guild settings readable from more than one place. A single repository layer with typed accessors, the way later bots do it, would have made that migration a one-time cost instead of a recurring question about which of two reads is authoritative.
And setup validation should have existed from the beginning. Most of the support load a bot of this size generates is a misconfigured token, a missing gateway intent or an invalid channel id. All three are detectable at boot, and none of them were, so every one of those arrived as a person describing a symptom.
References
- [Source repository]github.com/Uo1428/ALL-IN-ONE-Discord-Bot-
- [Author]Aryan (Uo1428)
Built with