toJson method

Map<String, dynamic> toJson()

Implementation

Map<String, dynamic> toJson() {
  if (name == null) {
    throw MissingPropertyException('Command name is required');
  }

  if (_description == null) {
    throw MissingPropertyException('Command description is required');
  }

  final List<Map<String, dynamic>> options = [
    for (final option in this.options) option.toJson(),
    for (final subCommand in subCommands) subCommand.toJson(),
    for (final group in groups) group.toJson(),
  ];

  return {
    'name': name,
    'name_localizations': _nameLocalizations,
    'description': _description,
    'description_localizations': _descriptionLocalizations,
    if (subCommands.isEmpty && groups.isEmpty)
      'type': CommandType.subCommand.value,
    'options': options,
  };
}