Table of Contents

Class SocketGuildUser

Namespace
Discord.WebSocket
Assembly
Discord.Net.WebSocket.dll

Represents a WebSocket-based guild user.

public class SocketGuildUser : SocketUser, IGuildUser, IUser, ISnowflakeEntity, IEntity<ulong>, IMentionable, IPresence, IVoiceState
Inheritance
SocketGuildUser
Implements
Inherited Members
Extension Methods

Properties

AudioStream

public AudioInStream AudioStream { get; }

Property Value

AudioInStream

AvatarId

Gets the identifier of this user's avatar.

public override string AvatarId { get; }

Property Value

string

DiscriminatorValue

Gets the per-username unique ID for this user. This will return 0 for users who have migrated to new username system.

public override ushort DiscriminatorValue { get; }

Property Value

ushort

DisplayAvatarId

Gets the displayed avatar for this user.

public string DisplayAvatarId { get; }

Property Value

string

The users displayed avatar hash. If the user does not have a guild avatar, this will be the regular avatar. If the user also does not have a regular avatar, this will be null.

DisplayName

Gets the displayed name for this user.

public string DisplayName { get; }

Property Value

string

A string representing the display name of the user; If the nickname is null, this will be the username.

Flags

Gets the public flags for this guild member.

public GuildUserFlags Flags { get; }

Property Value

GuildUserFlags

GlobalName

Gets the user's display name, if it is set. For bots, this will get the application name.

public override string GlobalName { get; }

Property Value

string

Remarks

This property will be null if user has no display name set.

Guild

Gets the guild the user is in.

public SocketGuild Guild { get; }

Property Value

SocketGuild

GuildAvatarId

Gets the guild specific avatar for this user.

public string GuildAvatarId { get; }

Property Value

string

The users guild avatar hash if they have one; otherwise null.

GuildPermissions

Gets the guild-level permissions for this user.

public GuildPermissions GuildPermissions { get; }

Property Value

GuildPermissions

A GuildPermissions structure for this user, representing what permissions this user has in the guild.

Hierarchy

Returns the position of the user within the role hierarchy.

public int Hierarchy { get; }

Property Value

int

Remarks

The returned value equal to the position of the highest role the user has, or MaxValue if user is the server owner.

IsBot

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

public override bool IsBot { get; }

Property Value

bool

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).

IsDeafened

Gets a value that indicates whether this user is deafened by the guild.

public bool IsDeafened { get; }

Property Value

bool

true if the user is deafened (i.e. not permitted to listen to or speak to others) by the guild; otherwise false.

IsMuted

Gets a value that indicates whether this user is muted (i.e. not permitted to speak via voice) by the guild.

public bool IsMuted { get; }

Property Value

bool

true if this user is muted by the guild; otherwise false.

IsPending

Whether the user has passed the guild's Membership Screening requirements.

public bool? IsPending { get; }

Property Value

bool?

IsSelfDeafened

Gets a value that indicates whether this user has marked themselves as deafened.

public bool IsSelfDeafened { get; }

Property Value

bool

true if this user has deafened themselves (i.e. not permitted to listen to or speak to others); otherwise false.

IsSelfMuted

Gets a value that indicates whether this user has marked themselves as muted (i.e. not permitted to speak via voice).

public bool IsSelfMuted { get; }

Property Value

bool

true if this user has muted themselves; otherwise false.

IsStreaming

Gets a value that indicates if this user is streaming in a voice channel.

public bool IsStreaming { get; }

Property Value

bool

true if the user is streaming; otherwise false.

IsSuppressed

Gets a value that indicates whether the user is muted by the current user.

public bool IsSuppressed { get; }

Property Value

bool

true if the guild is temporarily blocking audio to/from this user; otherwise false.

IsVideoing

Gets a value that indicates if the user is videoing in a voice channel.

public bool IsVideoing { get; }

Property Value

bool

true if the user has their camera turned on; otherwise false.

IsWebhook

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

public override bool IsWebhook { get; }

Property Value

bool

true if the user is a webhook; otherwise false.

JoinedAt

Gets when this user joined the guild.

public DateTimeOffset? JoinedAt { get; }

Property Value

DateTimeOffset?

A DateTimeOffset representing the time of which the user has joined the guild; null when it cannot be obtained.

Nickname

Gets the nickname for this user.

public string Nickname { get; }

Property Value

string

A string representing the nickname of the user; null if none is set.

PremiumSince

Gets the date and time for when this user's guild boost began.

public DateTimeOffset? PremiumSince { get; }

Property Value

DateTimeOffset?

A DateTimeOffset for when the user began boosting this guild; null if they are not boosting the guild.

RequestToSpeakTimestamp

Gets the time on which the user requested to speak.

public DateTimeOffset? RequestToSpeakTimestamp { get; }

Property Value

DateTimeOffset?

Roles

Returns a collection of roles that the user possesses.

public IReadOnlyCollection<SocketRole> Roles { get; }

Property Value

IReadOnlyCollection<SocketRole>

TimedOutUntil

Gets the date and time that indicates if and for how long a user has been timed out.

public DateTimeOffset? TimedOutUntil { get; }

Property Value

DateTimeOffset?

A DateTimeOffset indicating how long the user will be timed out for.

Remarks

null or a timestamp in the past if the user is not timed out.

Username

Gets the username for this user.

public override string Username { get; }

Property Value

string

VoiceChannel

Returns the voice channel the user is in, or null if none.

public SocketVoiceChannel VoiceChannel { get; }

Property Value

SocketVoiceChannel

VoiceSessionId

Gets the unique identifier for this user's voice session.

public string VoiceSessionId { get; }

Property Value

string

VoiceState

Gets the voice connection status of the user if any.

public SocketVoiceState? VoiceState { get; }

Property Value

SocketVoiceState?

A SocketVoiceState representing the user's voice status; null if the user is not connected to a voice channel.

Methods

AddRoleAsync(IRole, RequestOptions)

Adds the specified role to this user in the guild.

public Task AddRoleAsync(IRole role, RequestOptions options = null)

Parameters

role IRole

The role to be added to the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role addition operation.

AddRoleAsync(ulong, RequestOptions)

Adds the specified role to this user in the guild.

public Task AddRoleAsync(ulong roleId, RequestOptions options = null)

Parameters

roleId ulong

The role to be added to the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role addition operation.

AddRolesAsync(IEnumerable<IRole>, RequestOptions)

Adds the specified roles to this user in the guild.

public Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)

Parameters

roles IEnumerable<IRole>

The roles to be added to the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role addition operation.

AddRolesAsync(IEnumerable<ulong>, RequestOptions)

Adds the specified roleIds to this user in the guild.

public Task AddRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)

Parameters

roleIds IEnumerable<ulong>

The roles to be added to the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role addition operation.

GetDisplayAvatarUrl(ImageFormat, ushort)

Gets the display avatar URL for this user.

public override string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)

Parameters

format ImageFormat

The format of the image.

size ushort

The size of the image that matches any power of two, ranging from 16 to 2048.

Returns

string

A string representing the user's display avatar URL.

Remarks

This method will return GetDefaultAvatarUrl() if the user has no avatar set.

GetGuildAvatarUrl(ImageFormat, ushort)

Gets the guild-specific avatar URL for this user, if it is set.

public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)

Parameters

format ImageFormat

The format of the image.

size ushort

The size of the image that matches any power of two, ranging from 16 to 2048.

Returns

string

A string representing the user's guild-specific avatar URL; null if the user has no guild avatar set.

Remarks

tip

If you wish to retrieve the display avatar for this user, consider using GetDisplayAvatarUrl(ImageFormat, ushort).

GetPermissions(IGuildChannel)

Gets the level permissions granted to this user to a given channel.

public ChannelPermissions GetPermissions(IGuildChannel channel)

Parameters

channel IGuildChannel

The channel to get the permission from.

Returns

ChannelPermissions

A ChannelPermissions structure representing the permissions that a user has in the specified channel.

Examples

The following example checks if the current user has the ability to send a message with attachment in this channel; if so, uploads a file via SendFileAsync(string, string, bool, Embed, RequestOptions, bool, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags).

if (currentUser?.GetPermissions(targetChannel)?.AttachFiles)
    await targetChannel.SendFileAsync("fortnite.png");

KickAsync(string, RequestOptions)

Kicks this user from this guild.

public Task KickAsync(string reason = null, RequestOptions options = null)

Parameters

reason string

The reason for the kick which will be recorded in the audit log.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous kick operation.

ModifyAsync(Action<GuildUserProperties>, RequestOptions)

Modifies this user's properties in this guild.

public Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null)

Parameters

func Action<GuildUserProperties>

The delegate containing the properties to modify the user with.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous modification operation.

Remarks

This method modifies the current guild user with the specified properties. To see an example of this method and what properties are available, please refer to GuildUserProperties.

RemoveRoleAsync(IRole, RequestOptions)

Removes the specified role from this user in the guild.

public Task RemoveRoleAsync(IRole role, RequestOptions options = null)

Parameters

role IRole

The role to be removed from the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role removal operation.

RemoveRoleAsync(ulong, RequestOptions)

Removes the specified roleId from this user in the guild.

public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null)

Parameters

roleId ulong

The role to be removed from the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role removal operation.

RemoveRolesAsync(IEnumerable<IRole>, RequestOptions)

Removes the specified roles from this user in the guild.

public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)

Parameters

roles IEnumerable<IRole>

The roles to be removed from the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role removal operation.

RemoveRolesAsync(IEnumerable<ulong>, RequestOptions)

Removes the specified roleIds from this user in the guild.

public Task RemoveRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)

Parameters

roleIds IEnumerable<ulong>

The roles to be removed from the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous role removal operation.

RemoveTimeOutAsync(RequestOptions)

Removes the current timeout from the user in this guild if one exists.

public Task RemoveTimeOutAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous timeout removal operation.

SetTimeOutAsync(TimeSpan, RequestOptions)

Sets a timeout based on provided TimeSpan to this user in the guild.

public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null)

Parameters

span TimeSpan

The TimeSpan indicating how long a user should be timed out for.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous timeout creation operation.