Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Client Payload Injection

Adam Pine edited this page May 18, 2021 · 2 revisions

For each event a list of arguments is injected in your decorated method, you can type this list thanks to the ArgsOf<Event> type provided by discord.ts. You also receive other useful arguments after that:

  1. The event payload (ArgsOf<Event>)
  2. The Client instance
  3. The guards payload

You should use JS desctructuring for ArgsOf<Event> like in this example

import {
  Discord,
  On,
  Client,
  ArgsOf
} from "@typeit/discord";

@Discord()
abstract class AppDiscord {
  @On("message")
  private onMessage(
    [message]: ArgsOf<"message">, // Type message automatically
    client: Client, // Client instance injected here,
    guardPayload: any
  ) {
    // ...
  }
}