Skip to content

symfony/discord-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Sep 27, 2024
c62cd55 · Sep 27, 2024
Sep 25, 2024
Jun 20, 2024
Sep 23, 2024
Jul 6, 2024
Apr 3, 2021
Oct 13, 2022
Jul 23, 2024
Jun 20, 2024
Aug 9, 2021
Jan 24, 2023
Mar 25, 2023
Sep 23, 2024
Jun 2, 2021

Repository files navigation

Discord Notifier

Provides Discord integration for Symfony Notifier.

DSN example

DISCORD_DSN=discord://TOKEN@default?webhook_id=ID

where:

  • TOKEN the secure token of the webhook (returned for Incoming Webhooks)
  • ID the id of the webhook

Adding Interactions to a Message

With a Discord message, you can use the DiscordOptions class to add some interactive options called Embed elements.

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);

Resources