laravel-notification-channels / Discord

Licence: mit
Discord notification channel for Laravel

Projects that are alternatives of or similar to Discord

Laravel Ide Helper
Laravel IDE Helper
Stars: ✭ 11,893 (+7935.81%)
Mutual labels:  laravel
Lms Laravel
Laravel Learning Management System (LMS)
Stars: ✭ 148 (+0%)
Mutual labels:  laravel
Google Places Api
This is a PHP wrapper for Google Places API Web Service. And is Laravel Framework friendly.
Stars: ✭ 147 (-0.68%)
Mutual labels:  laravel
Laravel Nuxt Js
Build a SPA with Laravel and Nuxt.
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Technicsolder
PHP web app that brings incremental pack updates to the Technic Launcher and Technic Platform
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Laravel Disposable Email
Disposable email address validator for Laravel
Stars: ✭ 147 (-0.68%)
Mutual labels:  laravel
Translug
中文的 url slug 支持
Stars: ✭ 145 (-2.03%)
Mutual labels:  laravel
Servermonitor
💓 Laravel package to periodically monitor the health of your server and application.
Stars: ✭ 148 (+0%)
Mutual labels:  laravel
Deletediscordmessages
Undiscord - Delete all messages in a Discord channel or DM (Easy and fast) Bulk delete
Stars: ✭ 2,555 (+1626.35%)
Mutual labels:  discord
Messager
A convenient way to handle messages between users in a simple way
Stars: ✭ 147 (-0.68%)
Mutual labels:  laravel
React Laravel Boilerplate
A Laravel REST API backend with React/Redux, hot module reloading in development and route-level code splitting
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Speedy
🚄A Laravel Admin Package to create a website quickly
Stars: ✭ 146 (-1.35%)
Mutual labels:  laravel
Vaebot
Discord bot for everything from moderation to music.
Stars: ✭ 144 (-2.7%)
Mutual labels:  discord
Flarum
Simple forum software for building great communities.
Stars: ✭ 12,190 (+8136.49%)
Mutual labels:  laravel
Nitrosnipergo
Discord Nitro sniper and Giveaway joiner in Go (Faster than Python)
Stars: ✭ 146 (-1.35%)
Mutual labels:  discord
Laravue
Admin dashboard for enterprise Laravel applications built by VueJS and Element UI https://laravue.dev
Stars: ✭ 1,964 (+1227.03%)
Mutual labels:  laravel
Android App
An android application for reading novels
Stars: ✭ 146 (-1.35%)
Mutual labels:  discord
Blargbot
A multipurpose discord bot
Stars: ✭ 147 (-0.68%)
Mutual labels:  discord
Laravel Model Expires
A package to assign expiration dates to Eloquent models.
Stars: ✭ 148 (+0%)
Mutual labels:  laravel
Grosir Obat
Sebuah sistem kasir dan manajemen produk obat untuk penjualan Grosir
Stars: ✭ 147 (-0.68%)
Mutual labels:  laravel

Discord notification channel for Laravel 6.0+

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to send notifications using the Discord bot API with Laravel.

Contents

Installation

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,
],

Setting up your Discord bot

  1. Create a Discord application.

  2. Click the Create a Bot User button on your Discord application.

  3. 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',
    ],
    
  4. Add the bot to your server and identify it by running the artisan command:

    php artisan discord:setup
    

Usage

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:

  1. Your users table has two discord columns: discord_user_id and discord_private_channel_id
  2. When a user updates their Discord user ID (discord_user_id), generate and save a private channel ID (discord_private_channel_id)
  3. Return the user's discord_private_channel_id in the routeNotificationForDiscord method on the User model

You can generate direct message channels by using the getPrivateChannel method in the NotificationChannels\Discord\Discord class

use NotificationChannels\Discord\Discord;

class UserDiscordSettingsController
{
    public function store(Request $request)
    {
        $userId = $request->input('discord_user_id');
        $channelId = app(Discord::class)->getPrivateChannel($userId);

        Auth::user()->update([
            'discord_user_id' => $userId,
            'discord_private_channel_id' => $channelId,
        ]);
    }
}

Please take note that the getPrivateChannel method only accepts Discord's snowflake IDs. There is no API route provided by Discord to lookup a user's ID by their name and tag, and the process for copying and pasting a user ID can be confusing to some users. Because of this, it is recommended to add the option for users to connect their Discord account to their account within your application either by logging in with Discord or linking it to their pre-existing account.

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}**!");
    }
}

Available Message methods

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].