mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
e47cb68bc7cc616484af5f5037895d766ff40d14
- Add `defineCommand` function to validate and normalize command inputs. - Introduce `deployApplicationCommands` for deploying slash commands to Discord. - Create `CommandRegistry` class for managing command registration and retrieval. - Implement `buildSlashPayload` to construct slash command payloads with localization support. - Add usage utilities for prefix and slash commands. - Develop `CommandExecutor` to handle command execution with permission checks and cooldown management. - Create member message rendering service for welcome and leave messages with customizable templates. - Introduce presence template variables for dynamic bot status updates. - Implement template variable utilities for rendering and extracting variables from strings.
Discord.js v14 Framework Template
Professional command framework template for Discord.js 14.26.2 with:
- Single command object schema
- Minimal command authoring (
name,category,execute) - Optional per-user command cooldown (
cooldownin seconds) - Shared execution logic for prefix and slash
- External JSON i18n
- Automatic prefix and slash localizations from locale files
- One localized
nameper language drives both prefix and slash triggers - Typed argument schema
- User permission checks
- Auto-generated help from command metadata
Presence Storage
- The
presencecommand is persisted in PostgreSQL. - Storage is keyed by
bot_id(Discord user id), so one PostgreSQL instance can serve multiple bots. - Presence survives bot restarts and container restarts.
Setup
- Install dependencies: npm install
- Create environment file: cp .env.example .env
- Fill required values in
.env:DISCORD_TOKENDISCORD_CLIENT_IDDATABASE_URL
- Optional values:
DATABASE_SSL(truefor managed cloud DB,falsefor local Docker)PRESENCE_STREAM_URL(used when activity type isSTREAMING)AUTO_DEPLOY_SLASH(trueto sync slash commands on startup)DEV_GUILD_ID(optional guild scope for faster slash sync)
- Start in development: npm run dev
- Validate code quality:
- npm run typecheck
- npm run test
- npm run check
Docker Deployment (Bot + PostgreSQL)
- Configure
.envwith at least:DISCORD_TOKENDISCORD_CLIENT_IDPOSTGRES_DBPOSTGRES_USERPOSTGRES_PASSWORD
- Start stack: docker compose up -d --build
- Stop stack: docker compose down
By default, docker-compose.yml provisions:
bot: the Discord bot containerpostgres: PostgreSQL 16 with persistent volumepostgres_data
The bot container uses:
DATABASE_URL=postgresql://<POSTGRES_USER>:<POSTGRES_PASSWORD>@postgres:5432/<POSTGRES_DB>
Security defaults:
- PostgreSQL is bound to
127.0.0.1by default in Compose. - Keep strong values for
POSTGRES_PASSWORDand rotate credentials if exposed.
Multi-Bot With One DB
You can run several bot services against the same PostgreSQL instance.
- Keep one shared
postgresservice. - Add additional bot services with different
DISCORD_TOKEN/DISCORD_CLIENT_ID. - Keep
DATABASE_URLpointing to the same PostgreSQL service.
Because rows are keyed by bot_id, each bot keeps its own independent presence configuration.
An example with two bot services is available in docker-compose.multi-bot.example.yml.
Architecture
src/types/command.ts: strict command schemasrc/core/commands/defineCommand.ts: default command completionsrc/core/commands/registry.ts: trigger/name mapping generated from i18n dictionariessrc/core/commands/argParser.ts: prefix/slash args parsing from schemasrc/core/execution/CommandExecutor.ts: unified pipeline (permissions/cooldown/execute)src/handlers/prefixHandler.ts: prefix entrypointsrc/handlers/slashHandler.ts: slash entrypointsrc/database/presence/presenceStore.ts: PostgreSQL presence storagesrc/types/presenceTypes.ts: shared presence types/validationsrc/i18n/*.json: external i18n dictionariessrc/commands/*: business commands only (execute, optionalcooldown)
Included Commands
kiss(fun) with requireduserargping(utility)advanced(utility) with full argument/permission examplepresence(utility) with interactive status/activity/text panelhelp(core) with auto category and usage generation
Adding A Command
- Create a command object in
src/commands/... - Follow the schema in
src/types/command.ts - Add command to
src/commands/index.ts - If
AUTO_DEPLOY_SLASH=true, restart the bot to sync slash commands automatically
Description
Template Discord.js avec commandes prefix & slash auto, components v2, help auto, multi-langue et variables dynamiques (ex: {{bot_latency}}).
Readme
3.6 MiB
Languages
TypeScript
93.3%
JavaScript
3.2%
PLpgSQL
1.7%
CSS
0.9%
Dockerfile
0.9%