[Feature] Expose GetCurrentUser method & missing current user API methods (#2574)

* add stuff

* forgot to push

* docs

* Update DiscordRestClient.cs

* Apply suggestions from code review

* Update toc.yml

---------

Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com>
This commit is contained in:
Misha133
2023-02-06 19:20:54 +03:00
committed by GitHub
parent 2616d350ba
commit e3da96fbf5
13 changed files with 142 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
// fetch application role connection of the current user for the app with provided id.
var roleConnection = await client.GetUserApplicationRoleConnectionAsync(applicationid);
// create a new role connection metadata properties object & set some values.
var properties = new RoleConnectionProperties("Discord.Net Docs", "Cool Coding Guy")
.WithNumber("eaten_cookies", 69)
.WithBool("loves_cookies", true)
.WithDate("last_eaten_cookie", DateTimeOffset.UtcNow);
// update current user's values with the given properties.
await client.ModifyUserApplicationRoleConnectionAsync(applicationId, properties);

View File

@@ -0,0 +1,5 @@
// gets the user object stored in the DiscordRestClient.
var user = client.CurrentUser;
// fetches the current user with a REST call & updates the CurrentUser property.
var refreshedUser = await client.GetCurrentUserAsync();

View File

@@ -0,0 +1,2 @@
// fetches the current user's connections.
var connections = await client.GetConnectionsAsync();

View File

@@ -0,0 +1,6 @@
// fetches the current user's guild member object in a guild with provided id.
var member = await client.GetCurrentUserGuildMemberAsync(guildId);
// fetches the current user's guild member object in a RestUserGuild.
var guild = await client.GetGuildSummariesAsync().FlattenAsync().First();
var member = await guild.GetCurrentUserGuildMemberAsync();

View File

@@ -0,0 +1,2 @@
// fetches the guilds the current user participate in.
var guilds = await client.GetGuildSummariesAsync().FlattenAsync();

View File

@@ -0,0 +1,5 @@
using Discord;
using Discord.Rest;
await using var client = new DiscordRestClient();
await client.LoginAsync(TokenType.Bearer, "bearer token obtained through oauth2 flow");