GlobalCommandInteraction.fromPayload constructor
GlobalCommandInteraction.fromPayload(
- dynamic payload
Implementation
factory GlobalCommandInteraction.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 GlobalCommandInteraction(
payload['id'],
payload['data']['name'],
payload['application_id'],
payload['version'],
payload['type'],
payload['token'],
payload['member']?['user']?['id'] ?? payload['user']?['id'],
payload['guild_id'],
null,
payload['data']['name'],
payload['channel_id'],
payload['data'],
params
);
}