DiscordPHP Documentation

Message

Messages are present in channels and can be anything from a cross post to a reply and a regular message.

Properties

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!')->done(function (Message $message) {
    // ...
});

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()->done(function (Message $message) {
    // ...
});

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)->done(function (Message $message) {
    // ...
});

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

$message->react($emoji)->done(function () {
    // ...
});

// or

$message->react(':michael:251127796439449631')->done(function () {
    // ...
});

// or

$message->react('😀')->done(function () {
    // ...
});

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

Delete all reactions

$message->deleteReaction(Message::REACT_DELETE_ALL)->done(function () {
    // ...
});

Delete reaction by current user

$message->deleteReaction(Message::REACT_DELETE_ME, $emoji)->done(function () {
    // ...
});

Delete reaction by another user

$message->deleteReaction(Message::REACT_DELETE_ID, $emoji, 'member_id')->done(function () {
    // ...
});

Delete all reactions of one emoji

$message->deleteReaction(Message::REACT_DELETE_EMOJI, $emoji)->done(function () {
    // ...
});

Delete the message

Deletes the message. Returns nothing in a promise.

$message->delete()->done(function () {
    // ...
});

Edit the message

Updates the message. Takes a message builder. Returns the updated message in a promise.

$message->edit(MessageBuilder::new()
    ->setContent('new content'))->done(function (Message $message) {
        // ...
    });

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,
])->done(function (Collection $reactions) {
    foreach ($reactions as $reaction) {
        // ...
    }
});

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

$message->addEmbed($embed)->done(function (Message $message) {
    // ...
});

Search results