on<T extends DispatchEvent> method

StreamSubscription<T> on<T extends DispatchEvent>(
  1. void onData(
    1. T event
    )
)
inherited

A helper function to listen to events of a specific type.

Specifying the type parameter is important, as the callback will otherwise be invoked for every event received by the client.

The following two code examples are equivalent:

client.on<MessageCreateEvent>((event) => print(event.message.content));
client.onMessageCreate.listen((event) => print(event.message.content));

Implementation

StreamSubscription<T> on<T extends DispatchEvent>(void Function(T event) onData) => onEvent.whereType<T>().listen(onData);