Search Results for

    Show / Hide Table of Contents

    Interface IUser

    Represents a generic user.

    Inherited Members
    ISnowflakeEntity.CreatedAt
    IEntity<UInt64>.Id
    IMentionable.Mention
    IPresence.Status
    IPresence.ActiveClients
    IPresence.Activities
    Namespace: Discord
    Assembly: Discord.Net.Core.dll
    Syntax
    public interface IUser : ISnowflakeEntity, IEntity<ulong>, IMentionable, IPresence

    Properties

    | Improve this Doc View Source

    AvatarId

    Gets the identifier of this user's avatar.

    Declaration
    string AvatarId { get; }
    Property Value
    Type Description
    String
    | Improve this Doc View Source

    Discriminator

    Gets the per-username unique ID for this user.

    Declaration
    string Discriminator { get; }
    Property Value
    Type Description
    String
    | Improve this Doc View Source

    DiscriminatorValue

    Gets the per-username unique ID for this user.

    Declaration
    ushort DiscriminatorValue { get; }
    Property Value
    Type Description
    UInt16
    | Improve this Doc View Source

    IsBot

    Gets a value that indicates whether this user is identified as a bot.

    Declaration
    bool IsBot { get; }
    Property Value
    Type Description
    Boolean

    true if the user is a bot application; otherwise false.

    Remarks

    This property retrieves a value that indicates whether this user is a registered bot application (indicated by the blue BOT tag within the official chat client).

    | Improve this Doc View Source

    IsWebhook

    Gets a value that indicates whether this user is a webhook user.

    Declaration
    bool IsWebhook { get; }
    Property Value
    Type Description
    Boolean

    true if the user is a webhook; otherwise false.

    | Improve this Doc View Source

    PublicFlags

    Gets the public flags that are applied to this user's account.

    Declaration
    UserProperties? PublicFlags { get; }
    Property Value
    Type Description
    Nullable<UserProperties>

    The value of public flags for this user.

    Remarks

    This value is determined by bitwise OR-ing UserProperties values together.

    | Improve this Doc View Source

    Username

    Gets the username for this user.

    Declaration
    string Username { get; }
    Property Value
    Type Description
    String

    Methods

    | Improve this Doc View Source

    CreateDMChannelAsync(RequestOptions)

    Creates the direct message channel of this user.

    Declaration
    Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null)
    Parameters
    Type Name Description
    RequestOptions options

    The options to be used when sending the request.

    Returns
    Type Description
    Task<IDMChannel>

    A task that represents the asynchronous operation for getting or creating a DM channel. The task result contains the DM channel associated with this user.

    Remarks

    This method is used to obtain or create a channel used to send a direct message.

    warning

    In event that the current user cannot send a message to the target user, a channel can and will still be created by Discord. However, attempting to send a message will yield a HttpException with a 403 as its HttpCode. There are currently no official workarounds by Discord.

    Examples

    The following example attempts to send a direct message to the target user and logs the incident should it fail.

    public async Task MessageUserAsync(IUser user)
    {
        var channel = await user.CreateDMChannelAsync();
        try
        {
            await channel.SendMessageAsync("Awesome stuff!");
        }
        catch (Discord.Net.HttpException ex) when (ex.HttpCode == HttpStatusCode.Forbidden)
        {
            Console.WriteLine($"Boo, I cannot message {user}.");
        }
    }
    | Improve this Doc View Source

    GetAvatarUrl(ImageFormat, UInt16)

    Gets the avatar URL for this user.

    Declaration
    string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = null)
    Parameters
    Type Name Description
    ImageFormat format

    The format to return.

    UInt16 size

    The size of the image to return in. This can be any power of two between 16 and 2048.

    Returns
    Type Description
    String

    A string representing the user's avatar URL; null if the user does not have an avatar in place.

    Remarks

    This property retrieves a URL for this user's avatar. In event that the user does not have a valid avatar (i.e. their avatar identifier is not set), this method will return null. If you wish to retrieve the default avatar for this user, consider using GetDefaultAvatarUrl() (see example).

    Examples

    The following example attempts to retrieve the user's current avatar and send it to a channel; if one is not set, a default avatar for this user will be returned instead.

    | Improve this Doc View Source

    GetDefaultAvatarUrl()

    Gets the default avatar URL for this user.

    Declaration
    string GetDefaultAvatarUrl()
    Returns
    Type Description
    String

    A string representing the user's avatar URL.

    Remarks

    This property retrieves a URL for this user's default avatar generated by Discord (Discord logo followed by a random color as its background). This property will always return a value as it is calculated based on the user's DiscriminatorValue (discriminator % 5).

    Extension Methods

    UserExtensions.SendMessageAsync(IUser, String, Boolean, Embed, RequestOptions, AllowedMentions, MessageComponent, Embed[])
    UserExtensions.SendFileAsync(IUser, Stream, String, String, Boolean, Embed, RequestOptions, MessageComponent, Embed[])
    UserExtensions.SendFileAsync(IUser, String, String, Boolean, Embed, RequestOptions, MessageComponent, Embed[])
    UserExtensions.SendFileAsync(IUser, FileAttachment, String, Boolean, Embed, RequestOptions, MessageComponent, Embed[])
    UserExtensions.SendFilesAsync(IUser, IEnumerable<FileAttachment>, String, Boolean, Embed, RequestOptions, MessageComponent, Embed[])

    Theme

    • Improve this Doc
    • View Source
    In This Article
    Back to top Discord.Net (c) 2015-2022 3.9.0