Skip to content

Commit

Permalink
Handle missing command permissions error and return an empty array in…
Browse files Browse the repository at this point in the history
…stead
  • Loading branch information
abitofevrything committed Dec 28, 2023
1 parent 6ed9657 commit 62bb8d6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/src/http/managers/application_command_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:nyxx/src/builders/application_command.dart';
import 'package:nyxx/src/cache/cache.dart';
import 'package:nyxx/src/http/managers/manager.dart';
import 'package:nyxx/src/http/request.dart';
import 'package:nyxx/src/http/response.dart';
import 'package:nyxx/src/http/route.dart';
import 'package:nyxx/src/models/channel/channel.dart';
import 'package:nyxx/src/models/commands/application_command.dart';
Expand Down Expand Up @@ -259,11 +260,21 @@ class GuildApplicationCommandManager extends ApplicationCommandManager {
..permissions();
final request = BasicRequest(route);

final response = await client.httpHandler.executeSafe(request);
final permissions = parseCommandPermissions(response.jsonBody as Map<String, Object?>);

client.updateCacheWith(permissions);
return permissions;
try {
final response = await client.httpHandler.executeSafe(request);
final permissions = parseCommandPermissions(response.jsonBody as Map<String, Object?>);

client.updateCacheWith(permissions);
return permissions;
} on HttpResponseError catch (e) {
// 10066 = Unknown application command permissions
// Means there are no overrides for this command... why is this an error, Discord?
if (e.errorCode == 10066) {
return CommandPermissions(manager: this, id: id, applicationId: applicationId, guildId: guildId, permissions: []);
}

rethrow;
}
}

// TODO: Do we add the command permission endpoints?
Expand Down

0 comments on commit 62bb8d6

Please sign in to comment.