Download the PHP package arthurpar06/laravel-discord-notifier without Composer
On this page you can find all versions of the php package arthurpar06/laravel-discord-notifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arthurpar06/laravel-discord-notifier
More information about arthurpar06/laravel-discord-notifier
Files in arthurpar06/laravel-discord-notifier
Package laravel-discord-notifier
Short Description A strongly-typed way to send Discord notifications through Laravel's notification system, via webhooks or a bot.
License MIT
Homepage https://github.com/arthurpar06/laravel-discord-notifier
Informations about the package laravel-discord-notifier
Laravel Discord Notifier
A strongly-typed way to send Discord messages through Laravel's notification system — over a webhook or a bot — without ever hand-writing the Discord API payload again.
Your IDE and the type system remember the field names, the enums, and the limits — so you don't have to reopen the Discord docs every time.
Installation
Publish the config file:
To deliver via a bot, set your bot token in .env:
There is no default route — every notification declares where it goes.
Building a message
DiscordMessage models the Create Message body. Everything is fluent and typed:
Only the fields you set are sent. Discord's limits (≤10 embeds, content ≤2000 chars, embed field caps, the IS_COMPONENTS_V2 mutual-exclusivity rule, …) are validated when the message is serialized, with an exception that names the offending field.
Buttons
Attach buttons with ->button() (a single button in its own row) or ->actionRow() (up to five buttons per row, up to five rows per message). Buttons are built through a named constructor per style, so you can't assemble an invalid combination:
| Constructor | Style | Needs |
|---|---|---|
Button::link($url, $label = null) |
Link | a URL |
Button::primary/secondary/success/danger($customId, $label) |
interactive | a custom_id |
Button::premium($skuId) |
Premium | an SKU id |
All non-premium buttons also support ->disabled() and ->emoji('🔥') (or a custom emoji array).
Interactive buttons need your own interaction handling. This package only sends messages.
linkandpremiumbuttons work with nothing extra, butprimary/secondary/success/dangerbuttons raise a Discord Interaction when clicked — if your application does not answer it (via a gateway or an HTTP interactions endpoint) within three seconds, Discord shows "This interaction failed." Reach for link buttons unless you already run an interaction handler.
Sending notifications
In your notification, list discord in via() and return a DiscordMessage from toDiscord():
Route on demand
Pass a bot channel id (a guild channel or a user's DM channel) or an explicit route:
Route from a model
Give the notifiable a routeNotificationForDiscord() returning its own channel id — e.g. a stored private DM channel:
Returning null is safe: a notifiable with no route is skipped, so discord can
sit in a via() list alongside other channels even when only some of your users
have linked their account.
How routing is resolved
The route value is resolved to a transport, unambiguously:
| Route value | Transport |
|---|---|
DiscordRoute::webhook($url) / DiscordRoute::channel($id) |
as declared |
a string starting with http |
webhook |
| a numeric snowflake string | bot channel (POST /channels/{id}/messages) |
A DM to a user and a message to a guild channel are the same bot call — store the channel id and send.
When there is no route
| Situation | Result |
|---|---|
a notifiable returns null, '' or [] |
skipped — no message, no exception |
Notification::route('discord', '') |
throws — you asked for delivery but gave no destination |
any route that is neither a URL nor a snowflake (e.g. 'not-a-url') |
throws — a present-but-invalid route is a misconfiguration |
An absent route and a malformed one are different things. A model with nothing stored is ordinary and stays quiet; a value that was meant to be a destination and isn't fails loudly.
Testing
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-discord-notifier with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0