Interaction
extends Part
in package
Represents an interaction from Discord.
Tags
Table of Contents
Constants
- RESPONSE_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8
- RESPONSE_TYPE_CHANNEL_MESSAGE_WITH_SOURCE = 4
- RESPONSE_TYPE_DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5
- RESPONSE_TYPE_DEFERRED_UPDATE_MESSAGE = 6
- RESPONSE_TYPE_MODAL = 9
- RESPONSE_TYPE_PONG = 1
- RESPONSE_TYPE_PREMIUM_REQUIRED = 10
- RESPONSE_TYPE_UPDATE_MESSAGE = 7
- TYPE_APPLICATION_COMMAND = 2
- TYPE_APPLICATION_COMMAND_AUTOCOMPLETE = 4
- TYPE_MESSAGE_COMPONENT = 3
- TYPE_MODAL_SUBMIT = 5
- TYPE_PING = 1
Properties
- $app_permissions : ChannelPermission|null
- $application_id : string
- $channel : Channel|null
- $channel_id : string|null
- $created : bool
- Is the part already created in the Discord servers?
- $data : InteractionData|null
- $guild : Guild|null
- $guild_id : string|null
- $guild_locale : string|null
- $id : string
- $locale : string|null
- $member : Member|null
- $message : Message|null
- $scriptData : mixed
- Custom script data.
- $token : string
- $type : int
- $user : User|null
- $version : int
- $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.
- $responded : bool
- Whether we have responded to the interaction yet.
- $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
- Converts the part to a string.
- __unserialize() : void
- acknowledge() : PromiseInterface
- Acknowledges an interaction without returning a response.
- acknowledgeWithResponse() : PromiseInterface
- Acknowledges an interaction, creating a placeholder response message which can be edited later through the `updateOriginalResponse` function.
- autoCompleteResult() : PromiseInterface
- Responds to the interaction with auto complete suggestions.
- deleteFollowUpMessage() : PromiseInterface
- Deletes a follow up message.
- deleteOriginalResponse() : PromiseInterface
- Deletes the original interaction response.
- 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.
- getCreatableAttributes() : array<string|int, mixed>
- Returns the attributes needed to create.
- getDiscord() : Discord
- Get the Discord instance that owns this Part.
- getFollowUpMessage() : PromiseInterface<string|int, Message>
- Retrieves a non ephemeral follow up message.
- getOriginalResponse() : PromiseInterface<string|int, Message>
- Retrieves the original interaction response.
- 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.
- isPartial() : bool
- Whether the part is considered partial i.e. missing information which can be fetched from Discord.
- isResponded() : bool
- Returns true if this interaction has been internally responded.
- 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.
- respondWithMessage() : PromiseInterface
- Responds to the interaction with a message.
- sendFollowUpMessage() : PromiseInterface<string|int, Message>
- Sends a follow-up message to the interaction.
- serialize() : string|null
- Serializes the data. Used for Serializable.
- showModal() : PromiseInterface
- Responds to the interaction with a popup modal.
- unserialize() : void
- Unserializes some data and stores it. Used for Serializable.
- updateFollowUpMessage() : PromiseInterface<string|int, Message>
- Updates a non ephemeral follow up message.
- updateMessage() : PromiseInterface
- Updates the message that the interaction was triggered from.
- updateOriginalResponse() : PromiseInterface<string|int, Message>
- Updates the original interaction response.
- afterConstruct() : void
- Called after the part has been constructed.
- getAppPermissionsAttribute() : ChannelPermission|null
- Returns the permissions the app or bot has within the channel the interaction was sent from.
- getChannelAttribute() : Channel|Thread|null
- Returns the channel the interaction was invoked from.
- getDataAttribute() : InteractionData|null
- Returns the data associated with the interaction.
- getGuildAttribute() : Guild|null
- Returns the guild the interaction was invoked from.
- getMemberAttribute() : Member|null
- Returns the member who invoked the interaction.
- getMessageAttribute() : Message|null
- Returns the message that triggered the interaction, when triggered via message components.
- getUserAttribute() : User|null
- Returns the user who invoked the interaction.
- makeOptionalAttributes() : array<string|int, mixed>
- Return key-value attributes if it has been filled.
- respond() : PromiseInterface
- Responds to the interaction with a payload.
- 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
RESPONSE_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
public
mixed
RESPONSE_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
= 8
RESPONSE_TYPE_CHANNEL_MESSAGE_WITH_SOURCE
public
mixed
RESPONSE_TYPE_CHANNEL_MESSAGE_WITH_SOURCE
= 4
RESPONSE_TYPE_DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
public
mixed
RESPONSE_TYPE_DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
= 5
RESPONSE_TYPE_DEFERRED_UPDATE_MESSAGE
public
mixed
RESPONSE_TYPE_DEFERRED_UPDATE_MESSAGE
= 6
RESPONSE_TYPE_MODAL
public
mixed
RESPONSE_TYPE_MODAL
= 9
RESPONSE_TYPE_PONG
public
mixed
RESPONSE_TYPE_PONG
= 1
RESPONSE_TYPE_PREMIUM_REQUIRED
public
mixed
RESPONSE_TYPE_PREMIUM_REQUIRED
= 10
RESPONSE_TYPE_UPDATE_MESSAGE
public
mixed
RESPONSE_TYPE_UPDATE_MESSAGE
= 7
TYPE_APPLICATION_COMMAND
public
mixed
TYPE_APPLICATION_COMMAND
= 2
TYPE_APPLICATION_COMMAND_AUTOCOMPLETE
public
mixed
TYPE_APPLICATION_COMMAND_AUTOCOMPLETE
= 4
TYPE_MESSAGE_COMPONENT
public
mixed
TYPE_MESSAGE_COMPONENT
= 3
TYPE_MODAL_SUBMIT
public
mixed
TYPE_MODAL_SUBMIT
= 5
TYPE_PING
public
mixed
TYPE_PING
= 1
Properties
$app_permissions read-only
public
ChannelPermission|null
$app_permissions
Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
$application_id
public
string
$application_id
ID of the application the interaction is for.
$channel read-only
public
Channel|null
$channel
Channel the interaction was sent from.
$channel_id
public
string|null
$channel_id
ID of the channel the interaction was sent from.
$created
Is the part already created in the Discord servers?
public
bool
$created
= false
Whether the part has been created.
$data
public
InteractionData|null
$data
Data associated with the interaction.
$guild read-only
public
Guild|null
$guild
Guild the interaction was sent from.
$guild_id
public
string|null
$guild_id
ID of the guild the interaction was sent from.
$guild_locale
public
string|null
$guild_locale
The guild's preferred locale, if invoked in a guild.
$id
public
string
$id
ID of the interaction.
$locale
public
string|null
$locale
The selected language of the invoking user.
$member
public
Member|null
$member
Member who invoked the interaction.
$message
public
Message|null
$message
Message that triggered the interactions, when triggered from message components.
$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.
$token
public
string
$token
Continuation token for responding to the interaction.
$type
public
int
$type
Type of interaction.
$user
public
User|null
$user
User who invoked the interaction.
$version read-only
public
int
$version
Version of interaction.
$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', 'application_id', 'type', 'data', 'guild_id', 'channel', 'channel_id', 'member', 'user', 'token', 'version', 'message', 'app_permissions', 'locale', 'guild_locale']
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
= []
$responded
Whether we have responded to the interaction yet.
protected
bool
$responded
= false
$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()
Converts the part to a string.
public
__toString() : string
Tags
Return values
string —A JSON string of attributes.
__unserialize()
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
acknowledge()
Acknowledges an interaction without returning a response.
public
acknowledge() : PromiseInterface
Only valid for message component interactions.
Tags
Return values
PromiseInterfaceacknowledgeWithResponse()
Acknowledges an interaction, creating a placeholder response message which can be edited later through the `updateOriginalResponse` function.
public
acknowledgeWithResponse([bool $ephemeral = false ]) : PromiseInterface
Parameters
- $ephemeral : bool = false
-
Whether the acknowledge should be ephemeral.
Tags
Return values
PromiseInterfaceautoCompleteResult()
Responds to the interaction with auto complete suggestions.
public
autoCompleteResult(array<string|int, mixed>|array<string|int, Choice> $choices) : PromiseInterface
Parameters
- $choices : array<string|int, mixed>|array<string|int, Choice>
-
Autocomplete choices (max of 25 choices)
Tags
Return values
PromiseInterfacedeleteFollowUpMessage()
Deletes a follow up message.
public
deleteFollowUpMessage(string $message_id) : PromiseInterface
Parameters
- $message_id : string
-
Message to delete.
Tags
Return values
PromiseInterfacedeleteOriginalResponse()
Deletes the original interaction response.
public
deleteOriginalResponse() : PromiseInterface
Tags
Return values
PromiseInterfacefetch()
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
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
DiscordgetFollowUpMessage()
Retrieves a non ephemeral follow up message.
public
getFollowUpMessage(string $message_id) : PromiseInterface<string|int, Message>
Parameters
- $message_id : string
-
Message to get.
Tags
Return values
PromiseInterface<string|int, Message>getOriginalResponse()
Retrieves the original interaction response.
public
getOriginalResponse() : PromiseInterface<string|int, Message>
Tags
Return values
PromiseInterface<string|int, Message>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()
Gets the attributes to pass to repositories.
public
getRepositoryAttributes() : array<string|int, mixed>
Note: The order matters for repository tree (top to bottom).
Return values
array<string|int, mixed> —Attributes.
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
boolisResponded()
Returns true if this interaction has been internally responded.
public
isResponded() : bool
Return values
bool —The interaction is responded
jsonSerialize()
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.
respondWithMessage()
Responds to the interaction with a message.
public
respondWithMessage(MessageBuilder $builder[, bool $ephemeral = false ]) : PromiseInterface
Parameters
- $builder : MessageBuilder
-
Message to respond with.
- $ephemeral : bool = false
-
Whether the created message should be ephemeral.
Tags
Return values
PromiseInterfacesendFollowUpMessage()
Sends a follow-up message to the interaction.
public
sendFollowUpMessage(MessageBuilder $builder[, bool $ephemeral = false ]) : PromiseInterface<string|int, Message>
Parameters
- $builder : MessageBuilder
-
Message to send.
- $ephemeral : bool = false
-
Whether the created follow-up should be ephemeral. Will be ignored if the respond is previously ephemeral.
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.
showModal()
Responds to the interaction with a popup modal.
public
showModal(string $title, string $custom_id, array<string|int, mixed>|array<string|int, Component> $components[, callable|null $submit = null ]) : PromiseInterface
Parameters
- $title : string
-
The title of the popup modal, max 45 characters
- $custom_id : string
-
Developer-defined identifier for the component, max 100 characters
- $components : array<string|int, mixed>|array<string|int, Component>
-
Between 1 and 5 (inclusive) components that make up the modal contained in Action Row
- $submit : callable|null = null
-
The function to call once modal is submitted.
Tags
Return values
PromiseInterfaceunserialize()
Unserializes some data and stores it. Used for Serializable.
public
unserialize(string $data) : void
Parameters
- $data : string
-
Some serialized data.
Tags
updateFollowUpMessage()
Updates a non ephemeral follow up message.
public
updateFollowUpMessage(string $message_id, MessageBuilder $builder) : PromiseInterface<string|int, Message>
Parameters
- $message_id : string
-
Message to update.
- $builder : MessageBuilder
-
New message contents.
Tags
Return values
PromiseInterface<string|int, Message>updateMessage()
Updates the message that the interaction was triggered from.
public
updateMessage(MessageBuilder $builder) : PromiseInterface
Only valid for message component interactions.
Parameters
- $builder : MessageBuilder
-
The new message content.
Tags
Return values
PromiseInterfaceupdateOriginalResponse()
Updates the original interaction response.
public
updateOriginalResponse(MessageBuilder $builder) : PromiseInterface<string|int, Message>
Parameters
- $builder : MessageBuilder
-
New message contents.
Tags
Return values
PromiseInterface<string|int, Message>afterConstruct()
Called after the part has been constructed.
protected
afterConstruct() : void
getAppPermissionsAttribute()
Returns the permissions the app or bot has within the channel the interaction was sent from.
protected
getAppPermissionsAttribute() : ChannelPermission|null
Return values
ChannelPermission|nullgetChannelAttribute()
Returns the channel the interaction was invoked from.
protected
getChannelAttribute() : Channel|Thread|null
Return values
Channel|Thread|nullgetDataAttribute()
Returns the data associated with the interaction.
protected
getDataAttribute() : InteractionData|null
Return values
InteractionData|nullgetGuildAttribute()
Returns the guild the interaction was invoked from.
protected
getGuildAttribute() : Guild|null
Return values
Guild|null —null
when invoked via DM.
getMemberAttribute()
Returns the member who invoked the interaction.
protected
getMemberAttribute() : Member|null
Return values
Member|null —null
when invoked via DM.
getMessageAttribute()
Returns the message that triggered the interaction, when triggered via message components.
protected
getMessageAttribute() : Message|null
Return values
Message|nullgetUserAttribute()
Returns the user who invoked the interaction.
protected
getUserAttribute() : User|null
Return values
User|nullmakeOptionalAttributes()
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>respond()
Responds to the interaction with a payload.
protected
respond(array<string|int, mixed> $payload[, Multipart|null $multipart = null ]) : PromiseInterface
This is a separate function so that it can be overloaded when responding via webhook.
Parameters
- $payload : array<string|int, mixed>
-
Response payload.
- $multipart : Multipart|null = null
-
Optional multipart payload.
Tags
Return values
PromiseInterfacecheckForGetMutator()
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.