User
extends Part
in package
implements
Stringable
A user is a general user that is not attached to a guild.
Tags
Table of Contents
Interfaces
- Stringable
Constants
- BOT_HTTP_INTERACTIONS = 1 << 19
- FLAG_ACTIVE_DEVELOPER = 1 << 22
- FLAG_BUG_HUNTER_LEVEL_1 = 1 << 3
- FLAG_BUG_HUNTER_LEVEL_2 = 1 << 14
- FLAG_DISCORD_CERTIFIED_MODERATOR = 1 << 18
- FLAG_DISCORD_EMPLOYEE = 1 << 0
- FLAG_DISCORD_PARTNER = 1 << 1
- FLAG_EARLY_SUPPORTER = 1 << 9
- FLAG_HOUSE_BALANCE = 1 << 8
- FLAG_HOUSE_BRAVERY = 1 << 6
- FLAG_HOUSE_BRILLIANCE = 1 << 7
- FLAG_HYPESQUAD_EVENTS = 1 << 2
- FLAG_SUSPECTED_SPAM = 1 << 20
- FLAG_SYSTEM = 1 << 12
- FLAG_TEAM_USER = 1 << 10
- FLAG_VERIFIED_BOT = 1 << 16
- FLAG_VERIFIED_BOT_DEVELOPER = 1 << 17
- PREMIUM_NITRO = 2
- PREMIUM_NITRO_BASIC = 3
- PREMIUM_NITRO_CLASSIC = 1
- PREMIUM_NONE = 0
Properties
- $avatar : string|null
- $avatar_decoration : int|null
- $avatar_decoration_hash : int|null
- $avatar_hash : string|null
- $banner_hash : string|null
- $bot : bool|null
- $created : bool
- Is the part already created in the Discord servers?
- $discriminator : string
- $displayname : string
- $flags : int|null
- $global_name : string|null
- $id : string
- $locale : string|null
- $mfa_enabled : bool|null
- $premium_type : int|null
- $public_flags : int|null
- $scriptData : mixed
- Custom script data.
- $system : bool|null
- $username : string
- $verified : bool|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.
Methods
- __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
- broadcastTyping() : PromiseInterface
- Broadcasts that you are typing to the channel. Lasts for 5 seconds.
- createdTimestamp() : float|null
- Returns a timestamp for when a user's account was created.
- fetch() : PromiseInterface<string|int, static>
- Fetches any missing information about the part from Discord's servers.
- fill() : void
- Fills the parts attributes from an array.
- getAvatarAttribute() : string
- Returns the avatar URL for the client.
- getAvatarDecorationAttribute() : string|null
- Returns the avatar decoration URL for the client.
- getBannerAttribute() : string|null
- Returns the banner URL for the client.
- getCreatableAttributes() : array<string|int, mixed>
- Returns the attributes needed to create.
- getDiscord() : Discord
- Get the Discord instance that owns this Part.
- getPrivateChannel() : PromiseInterface<string|int, Channel>
- Gets the private channel for the user.
- 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>
- getUpdatableAttributes() : array<string|int, mixed>
- Returns the updatable attributes.
- 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.
- 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.
- sendMessage() : PromiseInterface<string|int, Message>
- sendMessage() : PromiseInterface<string|int, Message>
- Sends a message to the user.
- serialize() : string|null
- Serializes the data. Used for Serializable.
- unserialize() : void
- Unserializes some data and stores it. Used for Serializable.
- afterConstruct() : void
- Called after the part has been constructed.
- getAvatarDecorationHashAttribute() : string|null
- Returns the avatar decoration hash for the client.
- getAvatarHashAttribute() : string|null
- Returns the avatar hash for the client.
- getBannerHashAttribute() : string|null
- Returns the banner hash for the client.
- getDisplaynameAttribute() : string
- Returns the display name of the client.
- makeOptionalAttributes() : array<string|int, mixed>
- Return key-value attributes if it has been filled.
- checkForGetMutator() : string|false
- Checks if there is a get mutator present.
- checkForSetMutator() : string|false
- Checks if there is a set 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.
Constants
BOT_HTTP_INTERACTIONS
public
mixed
BOT_HTTP_INTERACTIONS
= 1 << 19
FLAG_ACTIVE_DEVELOPER
public
mixed
FLAG_ACTIVE_DEVELOPER
= 1 << 22
FLAG_BUG_HUNTER_LEVEL_1
public
mixed
FLAG_BUG_HUNTER_LEVEL_1
= 1 << 3
FLAG_BUG_HUNTER_LEVEL_2
public
mixed
FLAG_BUG_HUNTER_LEVEL_2
= 1 << 14
FLAG_DISCORD_CERTIFIED_MODERATOR
public
mixed
FLAG_DISCORD_CERTIFIED_MODERATOR
= 1 << 18
FLAG_DISCORD_EMPLOYEE
public
mixed
FLAG_DISCORD_EMPLOYEE
= 1 << 0
FLAG_DISCORD_PARTNER
public
mixed
FLAG_DISCORD_PARTNER
= 1 << 1
FLAG_EARLY_SUPPORTER
public
mixed
FLAG_EARLY_SUPPORTER
= 1 << 9
FLAG_HOUSE_BALANCE
public
mixed
FLAG_HOUSE_BALANCE
= 1 << 8
FLAG_HOUSE_BRAVERY
public
mixed
FLAG_HOUSE_BRAVERY
= 1 << 6
FLAG_HOUSE_BRILLIANCE
public
mixed
FLAG_HOUSE_BRILLIANCE
= 1 << 7
FLAG_HYPESQUAD_EVENTS
public
mixed
FLAG_HYPESQUAD_EVENTS
= 1 << 2
FLAG_SUSPECTED_SPAM
public
mixed
FLAG_SUSPECTED_SPAM
= 1 << 20
FLAG_SYSTEM
public
mixed
FLAG_SYSTEM
= 1 << 12
FLAG_TEAM_USER
public
mixed
FLAG_TEAM_USER
= 1 << 10
FLAG_VERIFIED_BOT
public
mixed
FLAG_VERIFIED_BOT
= 1 << 16
FLAG_VERIFIED_BOT_DEVELOPER
public
mixed
FLAG_VERIFIED_BOT_DEVELOPER
= 1 << 17
PREMIUM_NITRO
public
mixed
PREMIUM_NITRO
= 2
PREMIUM_NITRO_BASIC
public
mixed
PREMIUM_NITRO_BASIC
= 3
PREMIUM_NITRO_CLASSIC
public
mixed
PREMIUM_NITRO_CLASSIC
= 1
PREMIUM_NONE
public
mixed
PREMIUM_NONE
= 0
Properties
$avatar
public
string|null
$avatar
The avatar URL of the user.
$avatar_decoration
public
int|null
$avatar_decoration
The user's avatar decoration URL.
$avatar_decoration_hash
public
int|null
$avatar_decoration_hash
The user's avatar decoration hash.
$avatar_hash
public
string|null
$avatar_hash
The avatar hash of the user.
$banner_hash
public
string|null
$banner_hash
The banner hash of the user.
$bot
public
bool|null
$bot
Whether the user is a bot.
$created
Is the part already created in the Discord servers?
public
bool
$created
= false
Whether the part has been created.
$discriminator
public
string
$discriminator
The discriminator of the user.
$displayname
public
string
$displayname
The display name of the client.
$flags
public
int|null
$flags
User flags.
$global_name
public
string|null
$global_name
The user's display name, if it is set. For bots, this is the application name.
$id
public
string
$id
The unique identifier of the user.
$locale
public
string|null
$locale
User locale.
$mfa_enabled
public
bool|null
$mfa_enabled
Whether MFA is enabled.
$premium_type
public
int|null
$premium_type
Type of nitro subscription.
$public_flags
public
int|null
$public_flags
Public flags on the user.
$scriptData
Custom script data.
Relying on this variable with dynamic caching is discouraged.
public
mixed
$scriptData
Used for storing custom information, used by end products.
$system
public
bool|null
$system
Whether the user is a Discord system user.
$username
public
string
$username
The username of the user.
$verified
public
bool|null
$verified
Whether the user is verified.
$attributes
The parts attributes.
protected
array<string|int, mixed>
$attributes
= []
The parts attributes and content.
$discord
The Discord client.
protected
Discord
$discord
Client.
$factory
The factory.
protected
Factory
$factory
Factory.
$fillable
The parts fillable attributes.
protected
array<string|int, mixed>
$fillable
= ['id', 'username', 'discriminator', 'global_name', 'avatar', 'avatar_decoration', 'bot', 'system', 'mfa_enabled', 'locale', 'verified', 'email', 'flags', 'banner', 'accent_color', 'premium_type', 'public_flags']
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.
__debugInfo()
Handles debug calls from var_dump and similar functions.
public
__debugInfo() : array<string|int, mixed>
Tags
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
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
__toString()
Returns a formatted mention.
public
__toString() : string
Return values
string —A formatted mention.
__unserialize()
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
broadcastTyping()
Broadcasts that you are typing to the channel. Lasts for 5 seconds.
public
broadcastTyping() : PromiseInterface
Tags
Return values
PromiseInterfacecreatedTimestamp()
Returns a timestamp for when a user's account was created.
public
createdTimestamp() : float|null
Return values
float|nullfetch()
Fetches any missing information about the part from Discord's servers.
public
fetch() : PromiseInterface<string|int, static>
Tags
Return values
PromiseInterface<string|int, static>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.
Tags
getAvatarAttribute()
Returns the avatar URL for the client.
public
getAvatarAttribute([string|null $format = null ][, int $size = 1024 ]) : string
Parameters
- $format : string|null = null
-
The image format.
- $size : int = 1024
-
The size of the image.
Return values
string —The URL to the client's avatar.
getAvatarDecorationAttribute()
Returns the avatar decoration URL for the client.
public
getAvatarDecorationAttribute([string|null $format = null ][, int $size = 288 ]) : string|null
Parameters
- $format : string|null = null
-
The image format.
- $size : int = 288
-
The size of the image.
Return values
string|null —The URL to the clients avatar decoration.
getBannerAttribute()
Returns the banner URL for the client.
public
getBannerAttribute([string|null $format = null ][, int $size = 600 ]) : string|null
Parameters
- $format : string|null = null
-
The image format.
- $size : int = 600
-
The size of the image.
Return values
string|null —The URL to the clients banner.
getCreatableAttributes()
Returns the attributes needed to create.
public
getCreatableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getDiscord()
Get the Discord instance that owns this Part.
public
getDiscord() : Discord
Return values
DiscordgetPrivateChannel()
Gets the private channel for the user.
public
getPrivateChannel() : PromiseInterface<string|int, Channel>
Tags
Return values
PromiseInterface<string|int, Channel>getPublicAttributes()
Returns an array of public attributes.
public
getPublicAttributes() : array<string|int, mixed>
Tags
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()
public
getRepositoryAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getUpdatableAttributes()
Returns the updatable attributes.
public
getUpdatableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>isPartial()
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
public
isPartial() : bool
Return values
booljsonSerialize()
Provides data when the part is encoded into JSON. Used for JsonSerializable.
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
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
Attributes
- #[ReturnTypeWillChange]
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
offsetUnset()
Unsets an attribute via key. Used for ArrayAccess.
public
offsetUnset(string $key) : void
Parameters
- $key : string
-
The attribute key.
sendMessage()
public
sendMessage(MessageBuilder $builder) : PromiseInterface<string|int, Message>
Parameters
- $builder : MessageBuilder
Return values
PromiseInterface<string|int, Message>sendMessage()
Sends a message to the user.
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 ]) : PromiseInterface<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
Return values
PromiseInterface<string|int, Message>serialize()
Serializes the data. Used for Serializable.
public
serialize() : string|null
Return values
string|null —A string of serialized data.
unserialize()
Unserializes some data and stores it. Used for Serializable.
public
unserialize(string $data) : void
Parameters
- $data : string
-
Some serialized data.
Tags
afterConstruct()
Called after the part has been constructed.
protected
afterConstruct() : void
getAvatarDecorationHashAttribute()
Returns the avatar decoration hash for the client.
protected
getAvatarDecorationHashAttribute() : string|null
Return values
string|null —The client avatar decoration's hash.
getAvatarHashAttribute()
Returns the avatar hash for the client.
protected
getAvatarHashAttribute() : string|null
Return values
string|null —The client avatar's hash.
getBannerHashAttribute()
Returns the banner hash for the client.
protected
getBannerHashAttribute() : string|null
Tags
Return values
string|nullgetDisplaynameAttribute()
Returns the display name of the client.
protected
getDisplaynameAttribute() : string
Return values
string —Either global_name or username with optional #discriminator.
makeOptionalAttributes()
Return key-value attributes if it has been filled.
protected
makeOptionalAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
To be used with fields marked "optional?" from the API.
Parameters
- $attributes : array<string|int, mixed>
-
Names of optional attribute
Return values
array<string|int, mixed>checkForGetMutator()
Checks if there is a get mutator present.
private
checkForGetMutator(string $key) : string|false
Parameters
- $key : string
-
The attribute name to check.
Tags
Return values
string|false —Either a string if it is a method or false.
checkForSetMutator()
Checks if there is a set mutator present.
private
checkForSetMutator(string $key) : string|false
Parameters
- $key : string
-
The attribute name to check.
Tags
Return values
string|false —Either a string if it is a method or false.
getAttribute()
Gets an attribute on the part.
private
getAttribute(string $key) : mixed
Parameters
- $key : string
-
The key to the attribute.
Tags
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.
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.