Create Discord Event
Create one event module that exports event and aligns with the template event loader.
Workflow
- Confirm event intent.
- Determine target Discord event name, whether it should run once, and expected side effects.
- Check intent requirements before coding.
- If the event needs extra gateway intents (for example member or message events), update
src/client.tsin the same task.
- Choose event file location.
- Use
src/events/<event-name>.tsfor a new listener. - For complex implementations, prefer barrel-file organization by default: create
src/events/<group>/index.ts. - Keep one exported
eventobject per file.
- Implement typed event module.
- Import
Eventsfromdiscord.jsandEventfrom@/types. - Set
nameto a validEvents.*member. - Set
runOnce: trueonly for one-time startup-style handlers. - Keep
executeasync and type-safe for the selected event.
- Validate behavior.
- Ensure routing compatibility with dynamic loading in
src/utils/core.ts. - Run
npm run typecheck. - Run
npm run check.
Event Template
import { Events } from 'discord.js';
import type { Event } from '@/types';
export const event: Event<Events.ClientReady> = {
name: Events.ClientReady,
runOnce: true,
execute: async (client) => {
// Event logic
}
};
Constraints
- Use
@/path aliases for internal imports. - Export
eventexactly; dynamic loader expects this symbol. - Keep logging consistent with
logger.child({ name: 'events/<name>' })for non-trivial handlers.