Example bots
Whole bots built with MeoCord, what each one shows and where the Guide teaches it, and how to run one.
Before this
The MeoCord examples repository holds whole bots, each created as a new app and grown from there. The Guide's examples show one piece at a time; a bot shows the pieces working together, with its tests. Every bot is tested on each change and daily, with the meocord version its lockfile pins and with the newest release, so a release that breaks one shows up there first.
Feedback
A feedback form a server's staff approve or reject. /feedback opens a form, once every five minutes for each member.
A submitted form is posted to a review channel with Approve and Reject buttons, which only members with the
staff role can use. A verdict marks the post, removes its buttons, and tells the author by direct message.
- A slash command that opens a modal, and the modal's fields arriving in the handler's params, in
feedback.controller.ts. See Modals. - A cooldown of five minutes per member, in
feedback.controller.ts. See Cooldowns. - Buttons routed by a typed custom ID,
feedback/{id:int}/approve, inreview.controller.ts. See Typed params. - A guard on a whole controller that denies with a reason, in
staff.guard.tsandreview.controller.ts. See Where guards apply and Refusing a call. @Defer, which acknowledges a click and locks the post until the verdict is in, inreview.controller.ts. See @Defer.- Answers through
respond(), and aUserErrorshown only to the user who clicked, infeedback.service.ts. See Answering with respond() and Exception filters and UserError. - A presenter that draws MeoCord's own loading and error views in the theme's colours, in
app.presenter.ts. See Drawing a view and Reading the theme. - Tests of the whole app through
MeoCordTestingModule.fromAppanddispatch, with mock members, infeedback.spec.ts. See Testing the whole app.
Besides its token, the bot needs a staff role, and a channel for reviews where it has View Channel, Send Messages and
Embed Links, since each review is posted as an embed. Their IDs go in .env as STAFF_ROLE_ID and
FEEDBACK_CHANNEL_ID, and the bot stops as it starts if either is missing or isn't an ID. Feedback is kept in memory,
so a restart forgets it, and a review button left from before the restart says the feedback is gone.
Moderation
Warnings, timeouts and bans for a server's moderators, with every case logged in SQLite. /mod warn records a warning
at once; /mod timeout and /mod ban ask the moderator to confirm first, privately, and act only on Confirm.
/mod case shows a case and completes its number as you type, and the Apps menu lists a member's cases or warns a
message's author. Every action needs Moderate Members, a ban Ban Members too, and a moderator can act only on
members ranked below both them and the bot.
- Subcommands, each with its own handler, under one builder with default member permissions, in
mod.builder.tsandmod.controller.ts. See Subcommands. - A guard that reads a fact about its handler or controller,
@RequirePermission(...), made withcreateMetadata, inguards.ts. See Facts about the handler and Custom decorators. - A guard that compares the moderator's, the bot's and the member's highest roles, in
guards.ts. See Guards. - User and message context menus, in
mod.builder.tsandmod.controller.ts. See Context menus. - Confirmation buttons on a typed route,
mod/{ownerId:snowflake}/{case:int}/{action:confirm|cancel}, inmod.controller.ts. See Typed params. - Autocomplete for an integer option, in
mod.controller.ts. See Autocomplete. - An exception filter that turns Discord's refusal into words a moderator can act on, in
discord-refusal.filter.ts. See Exception filters and UserError. - A database provided under a token before login and closed as the bot stops, and a store that injects it, in
database.provider.tsandcase.store.ts. See A database. - A pending case taken once, with one
UPDATE … WHERE status = 'pending' RETURNING, incase.store.ts. See A moderation command. - Tests of the whole app through
dispatch, over a real SQLite database, a restart included, inmoderation.spec.ts. See Testing the whole app.
Besides its token, the bot needs Moderate Members and Ban Members, and its role above the members it moderates.
MODERATION_DB in .env sets where the case log is kept, moderation.db in the working directory unless set. The case
log uses node:sqlite, which ships with Node.js; on Node.js 22 it prints one experimental-feature warning as the bot
starts.
Running a bot
Every bot runs the same way, on Node.js 22.13 or later. It needs a bot token from the
Discord Developer Portal, and the bot invited to a server with the bot
and applications.commands scopes.
git clone https://github.com/meocord/examples.git
cd examples/feedback
npm ci
cp .env.example .env
npm run start:devgit clone https://github.com/meocord/examples.git
cd examples/feedback
bun ci
cp .env.example .env
bun run start:devgit clone https://github.com/meocord/examples.git
cd examples/feedback
pnpm install --frozen-lockfile
cp .env.example .env
pnpm start:devgit clone https://github.com/meocord/examples.git
cd examples/feedback
yarn install --immutable
cp .env.example .env
yarn start:devSet DISCORD_TOKEN and the bot's own settings in .env, which git ignores; never commit a token.
The token and the test server covers .env and
DEV_GUILD_ID. npm run start:dev watches the code, rebuilding and restarting the bot on each change. npm test
runs the bot's tests with mock interactions, with no Discord connection or token, and npm run build:prod followed by
npm start runs it as it runs in production.