Class User
- Namespace
- NetCord
- Assembly
- NetCord.dll
Represents a user of any interactable resource on Discord.
public class User : ClientEntity, IEntity, ISpanFormattable, IFormattable, IEquatable<Entity>, IJsonModel<JsonUser>
- Inheritance
-
User
- Implements
- Derived
- Inherited Members
Remarks
Users in Discord are generally considered the base entity and can be members of guilds, participate in text and voice chat, and much more. Users are separated by a distinction of 'bot' vs 'normal'. Bot users are automated users that are 'owned' by another user.
Constructors
User(JsonUser, RestClient)
public User(JsonUser jsonModel, RestClient client)
Parameters
jsonModel
JsonUserclient
RestClient
Properties
AccentColor
The user's banner color.
public Color? AccentColor { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
AvatarDecorationData
Data for the user's avatar decoration.
public AvatarDecorationData? AvatarDecorationData { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
AvatarHash
The user's avatar hash.
public string? AvatarHash { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
BannerHash
The user's banner hash.
public string? BannerHash { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
DefaultAvatarUrl
Returns an ImageUrl object representing the user's default avatar.
public ImageUrl DefaultAvatarUrl { get; }
Property Value
Discriminator
The user's Discord-tag.
public ushort Discriminator { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
The user's email.
public string? Email { get; }
Property Value
Remarks
Requires the email
OAuth2 scope.
Flags
The flags on a user's account.
public UserFlags? Flags { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
GlobalName
The user's display name, if it is set. For bots, this is the application name. Restrictions:
public string? GlobalName { get; }
Property Value
Remarks
- Must be between 1 and 32 characters long.
- Some zero-width and non-rendering characters are limited.
- Names are sanitized and trimmed of leading, trailing, and excessive internal whitespace.
identify
OAuth2 scope.
HasAvatar
Whether the user has a set custom avatar.
public bool HasAvatar { get; }
Property Value
HasAvatarDecoration
Whether the user has a set avatar decoration.
public bool HasAvatarDecoration { get; }
Property Value
HasBanner
Whether the user has a set custom banner image.
public bool HasBanner { get; }
Property Value
Id
The user's ID.
public override ulong Id { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
IsBot
Whether the user belongs to an application.
public bool IsBot { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
IsSystemUser
Whether the user is an Official Discord System user (part of the urgent message system).
public bool? IsSystemUser { get; }
Property Value
- bool?
Remarks
Requires the identify
OAuth2 scope.
Locale
The user's chosen language option.
public string? Locale { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
MfaEnabled
Whether the user has two factor enabled on their account.
public bool? MfaEnabled { get; }
Property Value
- bool?
Remarks
Requires the identify
OAuth2 scope.
PremiumType
The type of Nitro subscription on a user's account.
public PremiumType? PremiumType { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
PublicFlags
The public flags on a user's account.
public UserFlags? PublicFlags { get; }
Property Value
Remarks
Requires the identify
OAuth2 scope.
Username
The user's username, not unique across the platform. Restrictions:
public string Username { get; }
Property Value
Remarks
- Must be between 2 and 32 characters long.
-
Usernames cannot contain the following substrings:
@
,#
,:
,```
,discord
. -
Usernames cannot be:
everyone
orhere
.
identify
OAuth2 scope.
Verified
Whether the email on this account has been verified.
public bool? Verified { get; }
Property Value
- bool?
Remarks
Requires the email
OAuth2 scope.
Methods
GetAsync(RestRequestProperties?, CancellationToken)
public Task<User> GetAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
properties
RestRequestPropertiescancellationToken
CancellationToken
Returns
GetAvatarDecorationUrl()
Gets the ImageUrl of the user's avatar decoration.
public ImageUrl? GetAvatarDecorationUrl()
Returns
- ImageUrl
An ImageUrl pointing to the user's avatar decoration. If the user does not have one set, returns null.
GetAvatarUrl(ImageFormat?)
Gets the ImageUrl of the user's avatar.
public ImageUrl? GetAvatarUrl(ImageFormat? format = null)
Parameters
format
ImageFormat?The format of the returned ImageUrl. Defaults to Png (or Gif for animated avatars).
Returns
- ImageUrl
An ImageUrl pointing to the user's avatar. If the user does not have one set, returns null.
GetBannerUrl(ImageFormat?)
Gets the ImageUrl of the user's banner.
public ImageUrl? GetBannerUrl(ImageFormat? format = null)
Parameters
format
ImageFormat?The format of the returned ImageUrl. Defaults to Png (or Gif for animated banners).
Returns
- ImageUrl
An ImageUrl pointing to the user's banner. If the user does not have one set, returns null.
GetDMChannelAsync(RestRequestProperties?, CancellationToken)
public Task<DMChannel> GetDMChannelAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
properties
RestRequestPropertiescancellationToken
CancellationToken
Returns
ToString()
Converts the ID of this user into its string representation, using Discord's mention syntax (<@803169206115237908>
).
public override string ToString()
Returns
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
public override bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
Parameters
destination
Span<char>charsWritten
intformat
ReadOnlySpan<char>provider
IFormatProvider