DiscordPHP Documentation

Member extends Part
in package

A member is a relationship between a user and a guild. It contains user-to-guild specific data like roles.

Tags
link
https://discord.com/developers/docs/resources/guild#guild-member-object
since
2.0.0

Table of Contents

$activities  : Collection|array<string|int, Activity>
$avatar  : Array|null
$avatar_hash  : Array|null
$client_status  : object
$communication_disabled_until  : Carbon|null
$created  : bool
Is the part already created in the Discord servers?
$deaf  : bool
$discriminator  : string|null
$displayname  : string
$game  : Activity
$guild  : Guild|null
$guild_id  : string|null
$id  : string
$joined_at  : Carbon|null
$mute  : bool
$nick  : Array|null
$pending  : bool|null
$permissions  : RolePermission|null
$premium_since  : Carbon|null
$roles  : Collection|array<string|int, Role>
$scriptData  : mixed
Custom script data.
$status  : string
$user  : User|null
$username  : string|null
$attributes  : array<string|int, mixed>
The parts attributes.
$discord  : Discord
The Discord client.
$factory  : Factory
The factory.
$fillable  : array<string|int, mixed>
The parts fillable attributes.
$hidden  : array<string|int, mixed>
Attributes that are hidden from debug info.
$http  : Http
The HTTP client.
$repositories  : array<string|int, mixed>
An array of repositories that can exist in a part.
$repositories_cache  : array<string|int, mixed>
An array of repositories.
$visible  : array<string|int, mixed>
Attributes which are visible from debug info.
__construct()  : mixed
Create a new part instance.
__debugInfo()  : array<string|int, mixed>
Handles debug calls from var_dump and similar functions.
__get()  : mixed
Handles dynamic get calls onto the part.
__serialize()  : array<string|int, mixed>
__set()  : void
Handles dynamic set calls onto the part.
__toString()  : string
Returns a formatted mention.
__unserialize()  : void
addRole()  : ExtendedPromiseInterface
Adds a role to the member.
ban()  : ExtendedPromiseInterface<string|int, Ban>
Bans the member. Alias for `$guild->bans->ban()`.
ExtendedPromiseInterface()  : void
fetch()  : ExtendedPromiseInterface<string|int, self>
Fetches any missing information about the part from Discord's servers.
fill()  : void
Fills the parts attributes from an array.
getAvatarAttribute()  : string|null
Returns the guild avatar URL for the member.
getCreatableAttributes()  : array<string|int, mixed>
Returns the attributes needed to create.
getPermissions()  : RolePermission|null
Gets the total permissions of the member.
getPublicAttributes()  : array<string|int, mixed>
Returns an array of public attributes.
getRawAttributes()  : array<string|int, mixed>
Returns an array of raw attributes.
getRepositoryAttributes()  : array<string|int, mixed>
Gets the attributes to pass to repositories.
getUpdatableAttributes()  : array<string|int, mixed>
Returns the updatable attributes.
getVoiceChannel()  : Channel|null
Returns the voicechannel of the member.
isPartial()  : bool
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
jsonSerialize()  : array<string|int, mixed>
Provides data when the part is encoded into JSON. Used for JsonSerializable.
moveMember()  : ExtendedPromiseInterface<string|int, Member>
Moves the member to another voice channel.
offsetExists()  : bool
Checks if an attribute exists via key. Used for ArrayAccess.
offsetGet()  : mixed
Gets an attribute via key. Used for ArrayAccess.
offsetSet()  : void
Sets an attribute via key. Used for ArrayAccess.
offsetUnset()  : void
Unsets an attribute via key. Used for ArrayAccess.
removeRole()  : ExtendedPromiseInterface
Removes a role from the member.
sendMessage()  : ExtendedPromiseInterface<string|int, Message>
Sends a message to the member.
serialize()  : string|null
Serializes the data. Used for Serializable.
setNickname()  : ExtendedPromiseInterface<string|int, Member>
Sets the nickname of the member.
setRoles()  : ExtendedPromiseInterface<string|int, Member>
Updates member roles.
timeoutMember()  : ExtendedPromiseInterface<string|int, Member>
Sets timeout on a member.
unserialize()  : void
Unserializes some data and stores it. Used for Serializable.
afterConstruct()  : void
Called after the part has been constructed.
getActivitiesAttribute()  : Collection|array<string|int, Activity>
Gets the activities attribute.
getAvatarHashAttribute()  : Array|null
Returns the guild avatar hash for the member.
getCommunicationDisabledUntilAttribute()  : Carbon|null
Returns the communication disabled until attribute.
getDiscriminatorAttribute()  : string|null
Returns the discriminator attribute.
getDisplaynameAttribute()  : string
Returns the member nickname or username with the discriminator.
getGameAttribute()  : Activity
Gets the game attribute.
getGuildAttribute()  : Guild|null
Returns the guild attribute.
getIdAttribute()  : string
Returns the id attribute.
getJoinedAtAttribute()  : Carbon|null
Returns the joined at attribute.
getPermissionsAttribute()  : RolePermission|null
Returns the permissions attribute.
getPremiumSinceAttribute()  : Carbon|null
Returns the premium since attribute.
getRolesAttribute()  : Collection<string|int, ?\Discord\Parts\Guild\Role>
Returns the roles attribute.
getUserAttribute()  : User|null
Returns the user attribute.
getUsernameAttribute()  : string|null
Returns the username attribute.
checkForMutator()  : string|false
Checks if there is a mutator present.
getAttribute()  : mixed
Gets an attribute on the part.
setAttribute()  : void
Sets an attribute on the part.
studly()  : string
Converts a string to studlyCase.

Properties

$avatar

public Array|null $avatar

The avatar URL of the member or null if member has no guild avatar.

$avatar_hash

public Array|null $avatar_hash

The avatar hash of the member or null if member has no guild avatar.

$client_status

public object $client_status

Current client status.

$communication_disabled_until

public Carbon|null $communication_disabled_until

When the user's timeout will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out.

$created

Is the part already created in the Discord servers?

public bool $created = false

Whether the part has been created.

$deaf

public bool $deaf

Whether the member is deaf.

$discriminator read-only

public string|null $discriminator

The discriminator of the member.

$displayname read-only

public string $displayname

The nickname or username with discriminator of the member.

$guild read-only

public Guild|null $guild

The guild that the member belongs to.

$guild_id

public string|null $guild_id

The unique identifier of the guild that the member belongs to.

$id

public string $id

The unique identifier of the member.

$joined_at

public Carbon|null $joined_at

A timestamp of when the member joined the guild.

$mute

public bool $mute

Whether the member is mute.

$nick

public Array|null $nick

The nickname of the member.

$pending

public bool|null $pending

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

$permissions

public RolePermission|null $permissions

Total permissions of the member in the channel, including overwrites, returned when in the interaction object.

$premium_since

public Carbon|null $premium_since

When the user started boosting the server.

$scriptData

Custom script data.

public mixed $scriptData

Used for storing custom information, used by end products.

Tags
deprecated
10.0.0

Relying on this variable with dynamic caching is discouraged.

$status

public string $status

The status of the member.

$user

public User|null $user

The user part of the member.

$username read-only

public string|null $username

The username of the member.

$attributes

The parts attributes.

protected array<string|int, mixed> $attributes = []

The parts attributes and content.

$discord

The Discord client.

protected Discord $discord

Client.

$fillable

The parts fillable attributes.

protected array<string|int, mixed> $fillable = [ 'user', 'nick', 'avatar', 'roles', 'joined_at', 'premium_since', 'deaf', 'mute', 'pending', 'permissions', 'communication_disabled_until', // partial 'guild_id', // @internal 'id', 'status', 'activities', 'client_status', ]

The array of attributes that can be mass-assigned.

$hidden

Attributes that are hidden from debug info.

protected array<string|int, mixed> $hidden = []

Attributes that are hidden from public.

$http

The HTTP client.

protected Http $http

Client.

$repositories

An array of repositories that can exist in a part.

protected array<string|int, mixed> $repositories = []

Repositories.

$repositories_cache

An array of repositories.

protected array<string|int, mixed> $repositories_cache = []

$visible

Attributes which are visible from debug info.

protected array<string|int, mixed> $visible = []

Methods

__construct()

Create a new part instance.

public __construct(Discord $discord[, array<string|int, mixed> $attributes = [] ][, bool $created = false ]) : mixed
Parameters
$discord : Discord

The Discord client.

$attributes : array<string|int, mixed> = []

An array of attributes to build the part.

$created : bool = false

Whether the part has already been created.

Return values
mixed

__debugInfo()

Handles debug calls from var_dump and similar functions.

public __debugInfo() : array<string|int, mixed>
Tags
throws
Exception
see
Part::getPublicAttributes()

This function forwards onto getPublicAttributes.

Return values
array<string|int, mixed>

An array of public attributes.

__get()

Handles dynamic get calls onto the part.

public __get(string $key) : mixed
Parameters
$key : string

The attributes key.

Tags
throws
Exception
see
Part::getAttribute()

This function forwards onto getAttribute.

Return values
mixed

The value of the attribute.

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__set()

Handles dynamic set calls onto the part.

public __set(string $key, mixed $value) : void
Parameters
$key : string

The attributes key.

$value : mixed

The attributes value.

Tags
see
self::setAttribute()

This function forwards onto setAttribute.

Return values
void

__toString()

Returns a formatted mention.

public __toString() : string
Return values
string

__unserialize()

public __unserialize(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Return values
void

addRole()

Adds a role to the member.

public addRole(Role|string $role[, string|null $reason = null ]) : ExtendedPromiseInterface
Parameters
$role : Role|string

The role to add to the member.

$reason : string|null = null

Reason for Audit Log.

Tags
link
https://discord.com/developers/docs/resources/guild#add-guild-member-role
throws
RuntimeException
throws
NoPermissionsException

Missing manage_roles permission.

Return values
ExtendedPromiseInterface

ban()

Bans the member. Alias for `$guild->bans->ban()`.

public ban([int|null $daysToDeleteMessages = null ][, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Ban>
Parameters
$daysToDeleteMessages : int|null = null

The amount of days to delete messages from.

$reason : string|null = null

Reason of the Ban.

Tags
see
BanRepository::ban()
throws
RuntimeException

Member has no $guild

Return values
ExtendedPromiseInterface<string|int, Ban>

ExtendedPromiseInterface()

public ExtendedPromiseInterface() : void

<Message> sendMessage(MessageBuilder $builder)

Return values
void

fetch()

Fetches any missing information about the part from Discord's servers.

public fetch() : ExtendedPromiseInterface<string|int, self>
Tags
throws
RuntimeException

The part is not fetchable.

Return values
ExtendedPromiseInterface<string|int, self>

fill()

Fills the parts attributes from an array.

public fill(array<string|int, mixed> $attributes) : void
Parameters
$attributes : array<string|int, mixed>

An array of attributes to build the part.

Return values
void

getAvatarAttribute()

Returns the guild avatar URL for the member.

public getAvatarAttribute([string|null $format = null ][, int $size = 1024 ]) : string|null
Parameters
$format : string|null = null

The image format.

$size : int = 1024

The size of the image.

Return values
string|null

The URL to the member avatar or null.

getCreatableAttributes()

Returns the attributes needed to create.

public getCreatableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPermissions()

Gets the total permissions of the member.

public getPermissions([Channel|Thread|null $channel = null ]) : RolePermission|null

Note that Discord permissions are complex and YOU need to account for the fact that you cannot edit a role higher than your own.

Parameters
$channel : Channel|Thread|null = null

The channel to check its permission overwrites. null for just Role.

Tags
link
https://discord.com/developers/docs/topics/permissions
throws
InvalidArgumentException
Return values
RolePermission|null

null if permission is failed to be determined.

getPublicAttributes()

Returns an array of public attributes.

public getPublicAttributes() : array<string|int, mixed>
Tags
throws
Exception
Return values
array<string|int, mixed>

An array of public attributes.

getRawAttributes()

Returns an array of raw attributes.

public getRawAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

Raw attributes.

getRepositoryAttributes()

Gets the attributes to pass to repositories.

public getRepositoryAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

Attributes.

getVoiceChannel()

Returns the voicechannel of the member.

public getVoiceChannel() : Channel|null
Return values
Channel|null

isPartial()

Whether the part is considered partial i.e. missing information which can be fetched from Discord.

public isPartial() : bool
Return values
bool

jsonSerialize()

Provides data when the part is encoded into JSON. Used for JsonSerializable.

public jsonSerialize() : array<string|int, mixed>
Tags
throws
Exception
see
Part::getPublicAttributes()

This function forwards onto getPublicAttributes.

Return values
array<string|int, mixed>

An array of public attributes.

moveMember()

Moves the member to another voice channel.

public moveMember(Channel|Array $channel[, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Member>
Parameters
$channel : Channel|Array

The channel to move the member to.

$reason : string|null = null

Reason for Audit Log.

Return values
ExtendedPromiseInterface<string|int, Member>

offsetExists()

Checks if an attribute exists via key. Used for ArrayAccess.

public offsetExists(string $key) : bool
Parameters
$key : string

The attribute key.

Return values
bool

Whether the offset exists.

offsetGet()

Gets an attribute via key. Used for ArrayAccess.

public offsetGet(string $key) : mixed
Parameters
$key : string

The attribute key.

Tags
throws
Exception
see
Part::getAttribute()

This function forwards onto getAttribute.

Return values
mixed

offsetSet()

Sets an attribute via key. Used for ArrayAccess.

public offsetSet(string $key, mixed $value) : void
Parameters
$key : string

The attribute key.

$value : mixed

The attribute value.

Tags
see
Part::setAttribute()

This function forwards onto setAttribute.

Return values
void

offsetUnset()

Unsets an attribute via key. Used for ArrayAccess.

public offsetUnset(string $key) : void
Parameters
$key : string

The attribute key.

Return values
void

sendMessage()

Sends a message to the member.

public sendMessage(MessageBuilder|string $message[, bool $tts = false ][, Embed|array<string|int, mixed>|null $embed = null ][, array<string|int, mixed>|null $allowed_mentions = null ][, Message|null $replyTo = null ]) : ExtendedPromiseInterface<string|int, Message>

Takes a MessageBuilder or content of the message for the first parameter. If the first parameter is an instance of MessageBuilder, the rest of the arguments are disregarded.

Parameters
$message : MessageBuilder|string

The message builder that should be converted into a message, or the string content of the message.

$tts : bool = false

Whether the message is TTS.

$embed : Embed|array<string|int, mixed>|null = null

An embed object or array to send in the message.

$allowed_mentions : array<string|int, mixed>|null = null

Allowed mentions object for the message.

$replyTo : Message|null = null

Sends the message as a reply to the given message instance.

Tags
see
User::sendMessage()
throws
RuntimeException
Return values
ExtendedPromiseInterface<string|int, Message>

serialize()

Serializes the data. Used for Serializable.

public serialize() : string|null
Return values
string|null

A string of serialized data.

setNickname()

Sets the nickname of the member.

public setNickname([Array|null $nick = null ][, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Member>
Parameters
$nick : Array|null = null

The nickname of the member.

$reason : string|null = null

Reason for Audit Log.

Tags
throws
NoPermissionsException

Missing manage_nicknames permission.

Return values
ExtendedPromiseInterface<string|int, Member>

setRoles()

Updates member roles.

public setRoles(array<string|int, Role>|array<string|int, string> $roles[, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Member>
Parameters
$roles : array<string|int, Role>|array<string|int, string>

The roles to set to the member.

$reason : string|null = null

Reason for Audit Log.

Tags
link
https://discord.com/developers/docs/resources/guild#modify-guild-member
throws
NoPermissionsException

Missing manage_roles permission.

Return values
ExtendedPromiseInterface<string|int, Member>

timeoutMember()

Sets timeout on a member.

public timeoutMember(Carbon|null $communication_disabled_until[, string|null $reason = null ]) : ExtendedPromiseInterface<string|int, Member>
Parameters
$communication_disabled_until : Carbon|null

When the user's timeout will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out.

$reason : string|null = null

Reason for Audit Log.

Tags
throws
NoPermissionsException

Missing moderate_members permission.

Return values
ExtendedPromiseInterface<string|int, Member>

unserialize()

Unserializes some data and stores it. Used for Serializable.

public unserialize(string $data) : void
Parameters
$data : string

Some serialized data.

Tags
see
Part::setAttribute()

The unserialized data is stored with setAttribute.

Return values
void

afterConstruct()

Called after the part has been constructed.

protected afterConstruct() : void
Return values
void

getAvatarHashAttribute()

Returns the guild avatar hash for the member.

protected getAvatarHashAttribute() : Array|null
Return values
Array|null

The member avatar's hash or null.

getCommunicationDisabledUntilAttribute()

Returns the communication disabled until attribute.

protected getCommunicationDisabledUntilAttribute() : Carbon|null
Tags
throws
Exception
Return values
Carbon|null

getDiscriminatorAttribute()

Returns the discriminator attribute.

protected getDiscriminatorAttribute() : string|null
Return values
string|null

The discriminator of the member.

getDisplaynameAttribute()

Returns the member nickname or username with the discriminator.

protected getDisplaynameAttribute() : string
Return values
string

Nickname#Discriminator

getGameAttribute()

Gets the game attribute.

protected getGameAttribute() : Activity

Polyfill for the first activity.

Return values
Activity

getGuildAttribute()

Returns the guild attribute.

protected getGuildAttribute() : Guild|null
Return values
Guild|null

The guild.

getIdAttribute()

Returns the id attribute.

protected getIdAttribute() : string
Return values
string

The user ID of the member.

getJoinedAtAttribute()

Returns the joined at attribute.

protected getJoinedAtAttribute() : Carbon|null
Tags
throws
Exception
Return values
Carbon|null

The timestamp from when the member joined.

getPermissionsAttribute()

Returns the permissions attribute.

protected getPermissionsAttribute() : RolePermission|null

This is only available from Interaction, use Member::getPermissions() for normal permissions.

Tags
see
Member::getPermissions()
Return values
RolePermission|null

The total calculated permissions, only available from Interaction.

getPremiumSinceAttribute()

Returns the premium since attribute.

protected getPremiumSinceAttribute() : Carbon|null
Tags
throws
Exception
Return values
Carbon|null

getRolesAttribute()

Returns the roles attribute.

protected getRolesAttribute() : Collection<string|int, ?\Discord\Parts\Guild\Role>
Return values
Collection<string|int, ?\Discord\Parts\Guild\Role>

A collection of roles the member is in. null role only contains ID in the collection.

getUserAttribute()

Returns the user attribute.

protected getUserAttribute() : User|null
Return values
User|null

The user that owns the member.

getUsernameAttribute()

Returns the username attribute.

protected getUsernameAttribute() : string|null
Return values
string|null

The username of the member.

checkForMutator()

Checks if there is a mutator present.

private checkForMutator(string $key, string $type) : string|false
Parameters
$key : string

The attribute name to check.

$type : string

Either get or set.

Return values
string|false

Either a string if it is callable or false.

getAttribute()

Gets an attribute on the part.

private getAttribute(string $key) : mixed
Parameters
$key : string

The key to the attribute.

Tags
throws
Exception
Return values
mixed

Either the attribute if it exists or void.

setAttribute()

Sets an attribute on the part.

private setAttribute(string $key, mixed $value) : void
Parameters
$key : string

The key to the attribute.

$value : mixed

The value of the attribute.

Return values
void

studly()

Converts a string to studlyCase.

private static studly(string $string) : string

This is a port of updated Laravel's implementation, a non-regex with static cache. The Discord\studly() is kept due to unintended bug and we do not want to introduce BC by replacing it. This method is private static as we may move it outside this class in future.

Parameters
$string : string

The string to convert.

Tags
since
10.0.0
Return values
string

Search results