Another breaking change unfourtunately, due to various factors including the addition of thread support as well as future proofing for message components (buttons).
Sending messages is now done through the MessageBuilder
class.
See the documentation section on the message builder for usage.
This has been added to support a few features:
- Sending multiple embeds in a message.
- Sending multiple files in a message.
- Sending file attachments alongside embeds (e.g. images).
- Unifying
sendMessage
andsendFile
functions. - Adding message components.
The following functions have been changed, alongside their new signature:
Channel::sendMessage(MessageBuilder $message)
Member::sendMessage(MessageBuilder $message)
User::sendMessage(MessageBuilder $message)
// Old
$message->channel->sendMessage('hello, world!');
// New
$message->channel->sendMessage(MessageBuilder::new()
->setContent('hello, world!'));
The following functions have been added:
Message::edit(MessageBuilder $builder)
The following functions have been deprecated:
Channel::editMessage(Message $message, MessageBuilder $builder)
- deprecated in favour ofMessage::edit(MessageBuilder $builder)
.Channel::sendFile()
- deprecated in favour ofChannel::sendMessage(MessageBuilder $builder)
.Channel::getMessage(string $id)
- deprecated in favour ofChannel::messages::fetch(string $id)
.
With the addition of threads, messages can now be sent in text channels OR threads. These are not the same part.
If you depend on a function or property which is only present on Channel
, you should check the type of $message->channel
:
$discord->on('message', function (Message $message) {
if ($message->channel instanceof Channel) {
// is channel...
} else {
// is thread...
}
});
Message components (buttons, select menus) are now availabe! See the documentation on how to use implement these into your bot.