Message
Messages are present in channels and can be anything from a cross post to a reply and a regular message.
Properties
name | type | description |
---|---|---|
id | string | id of the message |
channel_id | string | id of the channel the message was sent in |
channel | Channel | channel the message was sent in | | |
guild_id | string or null | the unique identifier of the guild that the channel the message was sent in belongs to |
guild | Guild or null | the guild that the message was sent in | | |
content | string | content of the message |
type | int, Message constants | type of the message | | |
mentions | Collection of Users | users mentioned in the message | | |
author | User | the author of the message | | |
user_id | string | id of the user that sent the message |
member | Member | the member that sent this message, or null if it was in a private message | | |
mention_everyone | bool | whether @everyone was mentioned |
timestamp | Carbon
timestamp |
the time the message was sent |
edited_timestamp | Carbon
timestamp or null |
the time the message was edited or null if it hasn’t been edited |
tts | bool | whether text to speech was set when the message was sent |
attachments | Collection of Attachments | array of attachments | | |
embeds | Collection of Embeds | embeds contained in the message | | |
nonce | string | randomly generated string for client |
mention_roles | Collection of Roles | any roles that were mentioned in the message | | |
mention_channels | Collection of Channels | any channels that were mentioned in the message | | |
pinned | bool | whether the message is pinned |
reactions | reaction repository | any reactions on the message |
webhook_id | string | id of the webhook that sent the message |
activity | object | current message activity, requires rich present |
application | object | application of the message, requires rich presence |
application_id | string | if the message is a response to an Interaction, this is the id of the interaction’s application |
message_reference | object | message that is referenced by the message |
referenced_message | Message | the message that is referenced in a reply | | |
interaction | object | the interaction which triggered the message (application commands) |
thread | Thread | the thread that the message was sent in | | |
components | Component | sent if the message contains components like buttons, action rows, or other interactive components | | |
sticker_items | Sticker | stickers attached to the message | | |
flags | int | message flags, see below 5 properties |
crossposted | bool | whether the message has been crossposted |
is_crosspost | bool | whether the message is a crosspost |
suppress_embeds | bool | whether embeds have been supressed | ||
source_message_deleted | bool | whether the source message has been deleted e.g. crosspost |
urgent | bool | whether message is urgent |
has_thread | bool | whether this message has an associated thread, with the same id as the message |
ephemeral | bool | whether this message is only visible to the user who invoked the Interaction |
loading | bool | whether this message is an Interaction Response and the bot is “thinking” |
failed_to_mention_some_roles_in_thread | bool | this message failed to mention some roles and add their members to the thread |
Reply to a message
Sends a “reply” to the message. Returns the new message in a promise.
Parameters
name | type | description |
---|---|---|
text | string | text to send in the message |
$message->reply('hello!')->then(function (Message $message) {
// ...
})->done();
Crosspost a message
Crossposts a message to any channels that are following the channel the message was sent in. Returns the crossposted message in a promise.
$message->crosspost()->then(function (Message $message) {
// ...
})->done();
Reply to a message after a delay
Similar to replying to a message, also takes a delay
parameter in which the reply will be sent after. Returns the new message in a promise.
Parameters
name | type | description |
---|---|---|
text | string | text to send in the message |
delay | int | time in milliseconds to delay before sending the message |
// <@message_author_id>, hello! after 1.5 seconds
$message->delayedReply('hello!', 1500)->then(function (Message $message) {
// ...
})->done();
React to a message
Adds a reaction to a message. Takes an Emoji object, a custom emoji string or a unicode emoji. Returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
emoticon | Emoji or string | he emoji to react with |
$message->react($emoji)->then(function () {
// ...
})->done();
// or
$message->react(':michael:251127796439449631')->then(function () {
// ...
})->done();
// or
$message->react('😀')->then(function () {
// ...
})->done();
Delete reaction(s) from a message
Deletes reaction(s) from a message. Has four methods of operation, described below. Returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
type | int | type of deletion, one of Message::REACT_DELETE_ALL, Message::REACT_DELETE_ME, Message:REACT_DELETE_ID, Message::REACT_DELETE_EMOJI
|
emoticon | Emoji, string, null | emoji to delete, require if using DELETE_ID
, DELETE_ME
or DELETE_EMOJI
| |
|
id | string, null | id of the user to delete reactions for, required by DELETE_ID
|
Delete all reactions
$message->deleteReaction(Message::REACT_DELETE_ALL)->then(function () {
// ...
})->done();
Delete reaction by current user
$message->deleteReaction(Message::REACT_DELETE_ME, $emoji)->then(function () {
// ...
})->done();
Delete reaction by another user
$message->deleteReaction(Message::REACT_DELETE_ID, $emoji, 'member_id')->then(function () {
// ...
})->done();
Delete all reactions of one emoji
$message->deleteReaction(Message::REACT_DELETE_EMOJI, $emoji)->then(function () {
// ...
})->done();
Delete the message
Deletes the message. Returns nothing in a promise.
$message->delete()->then(function () {
// ...
})->done();
Edit the message
Updates the message. Takes a message builder. Returns the updated message in a promise.
$message->edit(MessageBuilder::new()
->setContent('new content'))->then(function (Message $message) {
// ...
})->done();
Note fields not set in the builder will not be updated, and will retain their previous value.
Create reaction collector
Creates a reaction collector. Works similar to Channel’s reaction collector. Takes a callback and an array of options. Returns a collection of reactions in a promise.
Options
At least one of time
or limit
must be specified.
name | type | description |
---|---|---|
time | int or false | time in milliseconds until the collector finishes |
limit | int or false | amount of reactions to be collected until the collector finishes |
$message->createReactionCollector(function (MessageReaction $reaction) {
// return true or false depending on whether you want the reaction to be collected.
return $reaction->user_id == '123123123123';
}, [
// will resolve after 1.5 seconds or 2 reactions
'time' => 1500,
'limit' => 2,
])->then(function (Collection $reactions) {
foreach ($reactions as $reaction) {
// ...
}
})->done();
Add embed to message
Adds an embed to a message. Takes an embed object. Will overwrite the old embed (if there is one). Returns the updated message in a promise.
Parameters
name | type | description |
---|---|---|
embed | Embed | he embed to add |
$message->addEmbed($embed)->then(function (Message $message) {
// ...
})->done();