Skip to content

Commit

Permalink
Add getInviteUrl extension for PartialApplications
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything committed Sep 23, 2024
1 parent 20443f1 commit 0f69513
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/nyxx_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export 'src/extensions/role.dart';
export 'src/extensions/scheduled_event.dart';
export 'src/extensions/snowflake_entity.dart';
export 'src/extensions/user.dart';
export 'src/extensions/application.dart';
23 changes: 23 additions & 0 deletions lib/src/extensions/application.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:nyxx/nyxx.dart';

/// Extensions on [PartialApplication]s.
extension ApplicationExtensions on PartialApplication {
/// Get a URL users can visit to add this bot to a guild.
Uri getInviteUri({
List<String> scopes = const ['bot', 'application.commands'],
Flags<Permissions>? permissions,
Snowflake? guildId,
bool? disableGuildSelect,
}) =>
Uri.https(
'discord.com',
'/oauth2/authorize',
{
'client_id': id.toString(),
'scope': scopes.join(' '),
if (permissions != null) 'permissions': permissions.value.toString(),
if (guildId != null) 'guild_id': guildId.toString(),
if (disableGuildSelect != null) 'disable_guild_select': disableGuildSelect,
},
);
}

0 comments on commit 0f69513

Please sign in to comment.