| Package Data | |
|---|---|
| Maintainer Username: | BennySama |
| Maintainer Contact: | cs475x@icloud.com (Cody Scott) |
| Package Create Date: | 2017-08-19 |
| Package Last Update: | 2017-08-20 |
| Home Page: | http://laravel-notification-channels.com |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-28 03:05:38 |
| Package Statistics | |
|---|---|
| Total Downloads: | 51 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 0 |
| Total Watchers: | 0 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
This package makes it easy to send notifications using the Discord bot API with Laravel 5.3.
You can install the package via composer:
composer require laravel-notification-channels/discord
Next, you must load the service provider:
// config/app.php
'providers' => [
// ...
NotificationChannels\Discord\DiscordServiceProvider::class,
],
Click the Create a Bot User button on your Discord application.
Paste your bot's API token, found under App Bot User, in your services.php config file:
// config/services.php
'discord' => [
'token' => 'YOUR_API_TOKEN',
],
Add the bot to your server and identify it by running the artisan command:
php artisan discord:setup
In every model you wish to be notifiable via Discord, you must add a channel ID property to that model accessible through a routeNotificationForDiscord method:
class Guild extends Eloquent
{
use Notifiable;
public function routeNotificationForDiscord()
{
return $this->discord_channel;
}
}
NOTE: Discord handles direct messages as though they are a regular channel. If you wish to allow users to receive direct messages from your bot, you will need to create a private channel with that user. An example workflow may look like the following:
- Your
userstable has two discord columns:discord_useranddiscord_channel- When a user updates their Discord user ID (
discord_user), generate and save a channel ID (discord_channel)- Return the user's
discord_channelin therouteNotificationForDiscordmethod on the User modelYou can generate direct message channels by using the
getPrivateChannelmethod inNotificationChannels\Discord\Discord:use NotificationChannels\Discord\Discord; // ... class UserDiscordSettingsController { public function store(Request $request) { $user = $request->input('discord_user'); $channel = app(Discord::class)->getPrivateChannel($user); Auth::user()->update([ 'discord_user' => $user, 'discord_channel' => $channel, ]); } }
You may now tell Laravel to send notifications to Discord channels in the via method:
// ...
use NotificationChannels\Discord\DiscordChannel;
use NotificationChannels\Discord\DiscordMessage;
class GameChallengeNotification extends Notification
{
public $challenger;
public $game;
public function __construct(Guild $challenger, Game $game)
{
$this->challenger = $challenger;
$this->game = $game;
}
public function via($notifiable)
{
return [DiscordChannel::class];
}
public function toDiscord($notifiable)
{
return DiscordMessage::create("You have been challenged to a game of *{$this->game->name}* by **{$this->challenger->name}**!");
}
}
body(string): Set the content of the message. (Supports basic markdown)embed(array): Set the embedded content. (View embed structure)Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email cs475x@icloud.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see LICENSE for more information.