How to write an event is in Events; every event, with what its function receives, is in Events reference.
event() is imported from 'chapterjs', in any file of src/. It takes one object, EventConfig: the name of the event, its options when it has some, and run. name types the rest: the same import line gives your function a member for 'memberJoin' and a role for 'roleDelete'.
src/events/welcome.ts
event()
src/; name says which event, and types what run receives. Some events have options, written next to name (bots: true, where: 'dm'): what run receives follows them.
Options is what the declaration wrote besides name and run, as written: an option that the event does not have is an error in the editor, and the declaration is also checked when it loads (see Errors).
Types
Ten types go withevent(): EventName, EventContexts and ContextOf for what your function receives, EventConfig for what it takes, EventDeclaration for what it returns, EventOptions, MessageEventOptions, ReactionEventOptions, WhereEventOptions and EventWhere for its options. All are imported with import type { ... } from 'chapterjs'.
EventName
name takes.
EventContexts
Message. To type what a declaration with given options receives, use ContextOf. Every entry is listed in the events reference.
ContextOf
event(). EventContexts is the widest form: every option on.
This is the type to use for a function shared by several declarations:
src/lib/log.ts
ContextOf<'messageCreate'> is what a declaration without options receives: a MemberMessage.
EventConfig
event(): the event, its options when it has some, and what to do. What run receives follows the options: what an option lets through is only there to handle when the option is on.
The options of the event, when it has some, are written next to them: see EventOptions.
EventDeclaration
event() returns: a declaration the framework finds in the exports of a file.
EventOptions
name, for the events that have some.
MessageEventOptions
Options of the events about messages.Also run for messages written by bots (this one included) and by webhooks. By default they are ignored: a bot that answers bots can end up answering itself, or another bot, forever.
Where the file listens:
'guild' (in servers, the default), 'dm' (in private messages with the bot) or 'both'. What the function receives follows it: a server that is always there, never there, or to check.ReactionEventOptions
Options of the events about reactions added or removed.Also run for the reactions of bots, this one included. By default they are ignored: a bot that reacts to reactions can end up answering its own, forever.
Where the file listens:
'guild' (in servers, the default), 'dm' (in private messages with the bot) or 'both'. What the function receives follows it: a server that is always there, never there, or to check.WhereEventOptions
The option of the events that also happen in private messages.Where the file listens:
'guild' (in servers, the default), 'dm' (in private messages with the bot) or 'both'. What the function receives follows it: a server that is always there, never there, or to check.EventWhere
'guild'), in private messages with the bot ('dm'), or in both.
Errors
A declaration that is not whatevent() expects is reported with its file (and the name of its export, when it is not the default one) when it loads, and never crashes the bot. In chapterjs dev, the declaration keeps its last working version, if it had one; in chapterjs build, the build fails.
No name
No name
A name that is not an event
A name that is not an event
Did you mean part is only there when a real event is close to the name.event() without an object
event() without an object
No run
No run
An option that does not exist
An option that does not exist
A wrong value
A wrong value
A named export
A named export
When the declaration is not the default export of its file, the name of the export follows the file: