Discord Notifications

Send to Channel

You can get notifications sent to various tools like Slack or Discord and even trigger workflows with Zapier. You can use the following code to get started with receiving notifications on Discord.

You can get a custom webhook right within you Discord server settings.

site/plugins/discord/index.php
<?php

Kirby::plugin('klub/discord', [
   'options' => [
      'webhook' => ''; // TODO: set you webhook URL here
   ],
   'hooks' => [
        'user.create:after' => function (User $user) {
            if ($user->isMember()) {
                site()->discord([
                    'content' => 'NEW Member: '.$user->nameOrEmail(),
                ]);
            }
        },
   ],
   'siteMethods' => [
        'discord' => function (array $data): bool {
            $webhook = option('klub.discord.webhook');
            if ($webhook) {
                $response = Remote::post($webhook, [
                    'headers' => [
                        'Accept' => 'application/json',
                        'Accept-Charset: utf8',
                    ],
                    'data' => $data,
                ]);

                return $response->code() === 204;
            }

            return false;
        },
    ],
    // other options
]);
Kirby Klub is not affiliated with the developers of Kirby CMS. We are merely standing on the shoulder of giants.
© 2024 Bruno Meilick All rights reserved.