Discord Notifier
Warning: You are browsing the documentation for Symfony 6.0, which is no longer maintained.
Consider upgrading your projects to Symfony 7.1.
Discord Notifier
The Discord Notifier package allows to use Discord via the Symfony Notifier component. Read the main Notifier docs to learn about installing and configuring that component.
Adding Interactions to a Message
With a Discord message, you can use the DiscordOptions class to add some interactive options called Embed elements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
use Symfony\Component\Notifier\Bridge\Discord\DiscordOptions;
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordEmbed;
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject;
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFooterEmbedObject;
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordMediaEmbedObject;
use Symfony\Component\Notifier\Message\ChatMessage;
$chatMessage = new ChatMessage('');
// Create Discord Embed
$discordOptions = (new DiscordOptions())
->username('connor bot')
->addEmbed((new DiscordEmbed())
->color(2021216)
->title('New song added!')
->thumbnail((new DiscordMediaEmbedObject())
->url('https://i.scdn.co/image/ab67616d0000b2735eb27502aa5cb1b4c9db426b'))
->addField((new DiscordFieldEmbedObject())
->name('Track')
->value('[Common Ground](https://open.spotify.com/track/36TYfGWUhIRlVjM8TxGUK6)')
->inline(true)
)
->addField((new DiscordFieldEmbedObject())
->name('Artist')
->value('Alasdair Fraser')
->inline(true)
)
->addField((new DiscordFieldEmbedObject())
->name('Album')
->value('Dawn Dance')
->inline(true)
)
->footer((new DiscordFooterEmbedObject())
->text('Added ...')
->iconUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Spotify_logo_without_text.svg/200px-Spotify_logo_without_text.svg.png')
)
)
;
// Add the custom options to the chat message and send the message
$chatMessage->options($discordOptions);
$chatter->send($chatMessage);
This work, including the code samples, is licensed under a
Creative Commons BY-SA 3.0
license.