CommandInteraction.fromPayload constructor

CommandInteraction.fromPayload(
  1. dynamic payload
)

Implementation

factory CommandInteraction.fromPayload(dynamic payload) {
  final Map<String, dynamic> params = {};
  void walk (List<dynamic> options) {
    for (final option in options) {
      if (option['options'] != null) {
        walk(option['options']);
      } else {
        params.putIfAbsent(option['name'], () => option['value']);
      }
    }
  }

  if (payload['data']?['options'] != null) {
    walk(payload['data']['options']);
  }

  return CommandInteraction(
    payload['id'],
    payload['data']['name'],
    payload['application_id'],
    payload['version'],
    payload['type'],
    payload['token'],
    payload['member']?['user']?['id'],
    payload['guild_id'],
    payload['data']['name'],
    payload['channel_id'],
    payload['data'],
    params
  );
}