DiscordPHP Documentation

AttachmentRequestBuilder extends Builder
in package
implements JsonSerializable

Helper class used to build attachment request payloads.

Tags
link
https://docs.discord.com/developers/resources/message#attachment-object-attachment-request-structure
since
10.51.0

Table of Contents

Interfaces

JsonSerializable

Properties

$description  : string|null
Description (alt text) for the file (max 1024 characters).
$duration_secs  : float|null
The duration of the audio or video file (required for voice messages).
$filename  : string|null
Name of the file attached.
$id  : string
Attachment id (snowflake or number).
$is_spoiler  : bool|null
Whether the attachment should be marked as a spoiler and blurred until clicked, this sets the `IS_SPOILER` attachment flag.
$title  : string|null
The title of the file.
$waveform  : string|null
Base64 encoded bytearray representing a sampled waveform (required for voice messages).

Methods

__get()  : mixed
Handles dynamic get calls onto the part.
__set()  : void
Handles dynamic set calls onto the part.
fromPart()  : self
Creates a new instance of the builder from a given Part.
getDescription()  : string|null
Get the description (alt text).
getDurationSecs()  : float|null
Get the duration in seconds.
getFilename()  : string|null
Get the filename.
getId()  : string
Returns the attachment id.
getIsSpoiler()  : bool|null
Returns whether the attachment is marked as a spoiler.
getTitle()  : string|null
Get the attachment title.
getWaveform()  : string|null
Get the waveform data.
jsonSerialize()  : array<string, mixed>
Returns the array representation of the attachment request used in Message Create/Edit payloads.
new()  : static
Creates a new attachment request builder with a required `id`.
setDescription()  : self
Set the description (alt text) for the file.
setDurationSecs()  : self
Set the duration of the audio or video file in seconds.
setFilename()  : self
Set the filename of the attachment.
setId()  : self
Set the attachment id.
setIsSpoiler()  : self
Mark the attachment as a spoiler.
setTitle()  : self
Set the title of the file.
setWaveform()  : self
Set the waveform data for voice messages.
checkForGetMutator()  : string|false
Checks if there is a get mutator present.
checkForSetMutator()  : string|false
Checks if there is a set mutator present.
getProperty()  : mixed
Gets a property on the parent part.
setProperty()  : void
Sets an property on the parent part.
studly()  : string
Converts a string to studlyCase.

Properties

$description

Description (alt text) for the file (max 1024 characters).

protected string|null $description

$duration_secs

The duration of the audio or video file (required for voice messages).

protected float|null $duration_secs

$id

Attachment id (snowflake or number).

protected string $id

For new attachments this must match the n in files[n].

$is_spoiler

Whether the attachment should be marked as a spoiler and blurred until clicked, this sets the `IS_SPOILER` attachment flag.

protected bool|null $is_spoiler

$waveform

Base64 encoded bytearray representing a sampled waveform (required for voice messages).

protected string|null $waveform

Methods

__get()

Handles dynamic get calls onto the part.

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

The attributes key.

Tags
throws
Exception
see
self::getAttribute()

This function forwards onto getAttribute.

Return values
mixed

The value of the attribute.

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

fromPart()

Creates a new instance of the builder from a given Part.

public static fromPart(Part $part) : self
Parameters
$part : Part
Return values
self

getDescription()

Get the description (alt text).

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

getDurationSecs()

Get the duration in seconds.

public getDurationSecs() : float|null
Return values
float|null

getId()

Returns the attachment id.

public getId() : string
Return values
string

$id Attachment id (or files index for new files).

getIsSpoiler()

Returns whether the attachment is marked as a spoiler.

public getIsSpoiler() : bool|null
Return values
bool|null

jsonSerialize()

Returns the array representation of the attachment request used in Message Create/Edit payloads.

public jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>

new()

Creates a new attachment request builder with a required `id`.

public static new(string $id) : static

For new attachments this must match the n in files[n].

Parameters
$id : string

Attachment id (or files index for new files).

Return values
static

setDescription()

Set the description (alt text) for the file.

public setDescription([string|null $description = null ]) : self
Parameters
$description : string|null = null

Description for the file (max 1024 characters).

Tags
throws
LengthException

Description exceeds 1024 characters.

Return values
self

setDurationSecs()

Set the duration of the audio or video file in seconds.

public setDurationSecs([float|null $seconds = null ]) : self

Required for voice messages.

Parameters
$seconds : float|null = null

Duration in seconds.

Return values
self

setFilename()

Set the filename of the attachment.

public setFilename([string|null $filename = null ]) : self
Parameters
$filename : string|null = null

Name of the file attached.

Return values
self

setId()

Set the attachment id.

public setId(string $id) : self

For new attachments this must match the n in files[n].

Parameters
$id : string

Attachment id (or files index for new files).

Return values
self

setIsSpoiler()

Mark the attachment as a spoiler.

public setIsSpoiler([bool|null $is_spoiler = null ]) : self

When true, the attachment will be blurred until clicked.

Parameters
$is_spoiler : bool|null = null
Return values
self

setTitle()

Set the title of the file.

public setTitle([string|null $title = null ]) : self
Parameters
$title : string|null = null

The title to set for the attachment.

Return values
self

setWaveform()

Set the waveform data for voice messages.

public setWaveform([string|null $waveform = null ]) : self
Parameters
$waveform : string|null = null

Base64 encoded sampled waveform.

Return values
self

checkForGetMutator()

Checks if there is a get mutator present.

protected checkForGetMutator(string $key) : string|false
Parameters
$key : string

The property name to check.

Return values
string|false

Either a string if it is a method or false.

checkForSetMutator()

Checks if there is a set mutator present.

protected checkForSetMutator(string $key) : string|false
Parameters
$key : string

The property name to check.

Return values
string|false

Either a string if it is a method or false.

getProperty()

Gets a property on the parent part.

protected getProperty(string $key) : mixed
Parameters
$key : string

The name of the property.

Tags
throws
Exception
Return values
mixed

Either the property if it exists or void.

setProperty()

Sets an property on the parent part.

protected setProperty(string $key, mixed $value) : void
Parameters
$key : string

The name of the property.

$value : mixed

The value of the property.

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. 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
On this page

Search results