Browse Source

Apply suggestions from code review

pull/2574/head
Casmir GitHub 2 years ago
parent
commit
618b484f2c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions
  1. +9
    -9
      docs/guides/bearer_token/bearer_token_guide.md
  2. +1
    -1
      docs/guides/bearer_token/samples/current_user.cs
  3. +1
    -1
      docs/guides/bearer_token/samples/current_user_connections.cs

+ 9
- 9
docs/guides/bearer_token/bearer_token_guide.md View File

@@ -5,26 +5,26 @@ title: Working with Bearer token


# Working with Bearer token # Working with Bearer token


Some endpoints in Discord API require a Bearer token, which can be obtained through [OAuth2 flow](https://discord.com/developers/docs/topics/oauth2). Discord.Net allows you to interact with these endopoints using [DiscordRestClient].
Some endpoints in Discord API require a Bearer token, which can be obtained through [OAuth2 flow](https://discord.com/developers/docs/topics/oauth2). Discord.Net allows you to interact with these endpoints using the [DiscordRestClient].


## Initializing a new instance of the client ## Initializing a new instance of the client
[!code-csharp[Initialize DiscordRestClient](samples/rest_client_init.cs)] [!code-csharp[Initialize DiscordRestClient](samples/rest_client_init.cs)]


## Getting current user ## Getting current user


[DiscordRestClient] gets the current user when `LoginAsync()` is called. The user object can be found in `CurrentUser` property.
The [DiscordRestClient] gets the current user when `LoginAsync()` is called. The user object can be found in the `CurrentUser` property.


If you need to fetch the user again `GetGetCurrentUserAsync()` method can be used.
If you need to fetch the user again, the `GetGetCurrentUserAsync()` method can be used.


[!code-csharp[Get current user](samples/current_user.cs)] [!code-csharp[Get current user](samples/current_user.cs)]


> [!NOTE] > [!NOTE]
> Some properies might be `null` depending on which scopes user authed your app with.
> Some properties might be `null` depending on which scopes users authorized your app with.
> For example: `email` scope is required to fetch current user's email address. > For example: `email` scope is required to fetch current user's email address.


## Fetching current user's guilds ## Fetching current user's guilds


`GetGuildSummariesAsync()` method is used to fetch current user's guilds. Since it returns an `IAsyncEnumerable` you need to call `FlattenAsync()` to get a plain `IEnumerable` containing [RestUserGuild] objects.
The `GetGuildSummariesAsync()` method is used to fetch current user's guilds. Since it returns an `IAsyncEnumerable` you need to call `FlattenAsync()` to get a plain `IEnumerable` containing [RestUserGuild] objects.


[!code-csharp[Get current user's guilds](samples/current_user_guilds.cs)] [!code-csharp[Get current user's guilds](samples/current_user_guilds.cs)]


@@ -33,7 +33,7 @@ If you need to fetch the user again `GetGetCurrentUserAsync()` method can be use


## Fetching current user's guild member object ## Fetching current user's guild member object


To fetch the current user's guild member object the `GetCurrentUserGuildMemberAsync()` method can be used.
To fetch the current user's guild member object, the `GetCurrentUserGuildMemberAsync()` method can be used.


[!code-csharp[Get current user's guild member](samples/current_user_guild_member.cs)] [!code-csharp[Get current user's guild member](samples/current_user_guild_member.cs)]


@@ -42,7 +42,7 @@ To fetch the current user's guild member object the `GetCurrentUserGuildMemberAs


## Get user connections ## Get user connections


`GetConnectionsAsync` method can be used to fetch current user's connections to other platforms.
The `GetConnectionsAsync` method can be used to fetch current user's connections to other platforms.


[!code-csharp[Get current user's connections](samples/current_user_connections.cs)] [!code-csharp[Get current user's connections](samples/current_user_connections.cs)]


@@ -51,9 +51,9 @@ To fetch the current user's guild member object the `GetCurrentUserGuildMemberAs


## Application role connection ## Application role connection


In addition to previous features Discord.Net supports fetching & updating user's application role conection metadata values. `GetUserApplicationRoleConnectionAsync()` returns a [RoleConnection] object of the current user for the given application id.
In addition to previous features, Discord.Net supports fetching & updating user's application role connection metadata values. `GetUserApplicationRoleConnectionAsync()` returns a [RoleConnection] object of the current user for the given application id.


`ModifyUserApplicationRoleConnectionAsync()` method is used to update current user's role connection metadata values. A new set of values can be created with [RoleConnectionProperties] object.
The `ModifyUserApplicationRoleConnectionAsync()` method is used to update current user's role connection metadata values. A new set of values can be created with [RoleConnectionProperties] object.


[!code-csharp[Get current user's connections](samples/app_role_connection.cs)] [!code-csharp[Get current user's connections](samples/app_role_connection.cs)]




+ 1
- 1
docs/guides/bearer_token/samples/current_user.cs View File

@@ -1,4 +1,4 @@
// gets the user object stored in DiscordRestClient.
// gets the user object stored in the DiscordRestClient.
var user = client.CurrentUser; var user = client.CurrentUser;


// fetches the current user with a REST call & updates the CurrentUser property. // fetches the current user with a REST call & updates the CurrentUser property.

+ 1
- 1
docs/guides/bearer_token/samples/current_user_connections.cs View File

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

Loading…
Cancel
Save