Giter VIP home page Giter VIP logo

discord's People

Contributors

atymic avatar bennysama avatar codyphobe avatar corsair avatar deto1986 avatar dmyers avatar freekmurze avatar gummibeer avatar jaybizzle avatar jee7 avatar kawax avatar laravel-shift avatar lloricode avatar m1guelpf avatar maartenvw avatar messerli90 avatar mpociot avatar nullx27 avatar owenvoke avatar ricardoboss avatar romulosalmeida avatar xheinrich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord's Issues

Config not recognized ?!?!

Everything its ok:
image

But when I run
php artisan discord:setup

Receive:
You must paste your Discord token (App Bot User token) into your services.php config file.

What is wrong ?

Discord error response data discarded

Discord sends back data in the response body when there is a rate limit error.
See: https://discord.com/developers/docs/topics/rate-limits

They say that you should not hard code the retry timeout:

Because we may change rate limits at any time and rate limits can be different per application, rate limits should not be hard coded into your bot/application. In order to properly support our dynamic rate limits, your bot/application should parse for our rate limits in response headers and locally prevent exceeding the limits as they change.

Right now the RequestException is caught and a CouldNotSendNotification exception is thrown. The latter only includes the message keyword from the response sent by Discord API. The other keywords like retry_after and global are being discarded.

One fix for this could be to include the original RequestException exception as the previous exception to the thrown CouldNotSendNotification. Exceptions have 3 constructor arguments, the message, code and previous exception. Only the message part is currently used. Setting the previous exception should make it possible for the Laravel app to get the body of the original Discord response from the original exception and parse out the retry_after or other data.

Discord Bot Always Offline

The Discord Bot always online, but still can send the notification. Any idea how to make the bot online?

Class 'NotificationChannels\Discord\DiscordServiceProvider' not found

Hi

i am trying your package and i cant proceed in setting up the discord bot cause i keep receiving this error in my php artisan...

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'NotificationChannels\Discord\DiscordServiceProvider' not found

i have put this in app.php
NotificationChannels\Discord\DiscordServiceProvider::class

thanks in advance :D

How to test

I wanted to test the bot using your code. In your example you simply have $ composer test. I have no clue how to start this although I got it unto my discord server it doesn't stay.

Release new version for Laravel 5.8

I just rolled out a new Laravel app and wanted to add discord notifications support, went to install the package and simply running composer require laravel-notification-channels/discord results in the package failing to install due to the illuminate/queue requirements.

As 5.8 support was recently added in 397a25b could you publish a new release to support this officially?

In the meanwhile as a workaround for anyone else experiencing this, you can use composer require laravel-notification-channels/discord:dev-master to install it.

Driver [Discord] not supported

I'm having some issues getting this package to be supported in my project. I'm working inside a Laravel 8 application and am using PHP 7.4, I'm using version 1.3.0 of this package and have just set it up, my notification class (the important bits) looks like this...

<?php

namespace App\Notifications\Monitor;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Messages\NexmoMessage;

use NotificationChannels\Discord\DiscordChannel;
use NotificationChannels\Discord\DiscordMessage;
use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterDirectMessage;

use App\Models\NotificationHistory;
use App\Traits\Plans;

class MonitorDown extends Notification implements ShouldQueue
{
    use Queueable, Plans;

    public $monitor;
    public $emailData;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($monitor, $emailData)
    {
        $this->monitor = $monitor;
        $this->emailData = $emailData;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        $preferences = json_decode($notifiable->notification_preferences);

        if (!$notifiable->is_subscribed) {
            $preferences->monitors->down = array_merge(array_diff($preferences->monitors->down, [
                'nexmo', 'discord', 'twitter'
            ]));
        }

        // not working
        return ['twitter', 'discord'];

        // not working
        return [DiscordChannel::class, 'discord'];

        // not working
        return [DiscordChannel::class];
        
        // return $preferences->monitors->down;
    }

    /**
     * Determine which queues should be used for each notification channel.
     *
     * @return array
     */
    public function viaQueues()
    {
        return [
            'mail' => 'notifications',
            'database' => 'notifications',
            'slack' => 'notifications',
            'nexmo' => 'notifications',
            'discord' => 'notifications',
            'twitter' => 'notifications'
        ];
    }

    /**
 * Get the Discord representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toDiscord($notifiable)
{
    $data = [
        'type' => 'monitor-down',
        'name' => $this->emailData['monitor_name'],
        'url' => $this->emailData['monitor_url'],
        'value' => 'down'
    ];

    try {
        $this->createHistoryEntry('discord', 'Monitor Down', $data, $notifiable);
    } catch (\Exception $e) { }

    $monitorName = $this->emailData['monitor_name'];
    $monitorURL = $this->emailData['monitor_url'];

    return DiscordMessage::create("Your monitor $monitorName -- ($monitorURL) -- has just gone DOWN");
}

    /**
     * Create a history entry
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function createHistoryEntry($method = 'database', $type = '', $data, $notifiable)
    {
        try {
            $history = new NotificationHistory();
            $history->method = $method;
            $history->type = $type;
            $history->data = json_encode($data);
            $history->notification_id = isset($this->id) ? $this->id : '';
            $history->user_id = $notifiable['id'];
            $history->save();
        } catch (\Exception $e) { }
    }
}

You'll see that I've tried several ways to get the notifications to work:

// not working
return ['twitter', 'discord'];

// not working
return [DiscordChannel::class, 'discord'];

// not working
return [DiscordChannel::class];

But still, the error returned is:

InvalidArgumentException: Driver [discord] not supported.

Update github description

This is a silly thing, but the description in github says Discord notification channel for Laravel 5.3 while the readme says Discord notification channel for Laravel 5.6.

This may be turning away people who don't scroll down and confuse people who don't read the readme closely.

When deployed on hosting

When i deployed on hosting i got an error
On PC all works

NotificationChannels \ Discord \ Exceptions \ CouldNotSendNotification
Discord responded with an HTTP error: 401: 401: Unauthorized

Code review

Ping me when you're done with the code, tests and readme. I'll do a little code review and publish your package on Packagist.

Laravel 9 Compatibility

I tried updating to Laravel 9 but having conflicts with

illuminate/queue and laravel/framework packages.

Only one of these can be installed: illuminate/queue[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev], laravel/framework[v9.0.0-beta.1, ..., 9.x-dev]. laravel/framework replaces illuminate/queue and thus cannot coexist with it.

Could not open socket to "gateway.discord.gg:443"

I tried running php artisan discord:setup and got this output:


 Is the bot already added to your server? (yes/no) [no]:
 >

 What is your Discord app client ID?:
 > <client_id>

Add the bot to your server by visiting this link: https://discordapp.com/oauth2/authorize?&client_id=<client_id>&scope=bot&permissions=0

 Continue? (yes/no) [yes]:
 >

Attempting to identify the bot with Discord's websocket gateway...
Could not get a websocket gateway address, defaulting to 'wss://gateway.discord.gg'.
Connecting to 'wss://gateway.discord.gg'...

   WebSocket\ConnectionException  : Could not open socket to "gateway.discord.gg:443":  (0).

  at S:\repos\totoro\vendor\textalk\websocket\lib\Client.php:60
    56|     // Open the socket.  @ is there to supress warning that we will catch in check below instead.
    57|     $this->socket = @fsockopen($host_uri, $port, $errno, $errstr, $this->options['timeout']);
    58| 
    59|     if ($this->socket === false) {
  > 60|       throw new ConnectionException(
    61|         "Could not open socket to \"$host:$port\": $errstr ($errno)."
    62|       );
    63|     }
    64| 

  Exception trace:

  1   WebSocket\Client::connect()
      S:\repos\totoro\vendor\textalk\websocket\lib\Base.php:30

  2   WebSocket\Base::send("{"op":2,"d":{"token":"<bot api token>","v":3,"compress":false,"properties":{"$os":"WINNT","$browser":"laravel-notification-channels-discord","$device":"laravel-notification-channels-discord","$
referrer":"","$referring_domain":""}}}")
      S:\repos\totoro\vendor\laravel-notification-channels\discord\src\Commands\SetupCommand.php:96

  Please use the argument -v to see more details.

Could this happen because the gateway version is too old? I had a quick look at the discord dev portal and saw the latest version is 6, not 3 as used in the request.

Discord webhook support per user

I've seen a few webhook questions on here before, but I'm sure the assumption here is a one app, one system approach. What I have is a notifications systems, whereby every customer on my platform needs to integrate Discord, so, the webhook will be different per user, and they'll set it on their profile.

How can I send a notification then to their webhook's url channel?

This is my current routing on my User model to obtain their webhook:

/**
 * Route notifications for the Discord channel.
 */
public function routeNotificationForDiscord($notification)
{
    try {
        $availableIntegration = AvailableIntegration::where('slug', 'discord')
                                                    ->first();

        $userIntegration = UserIntegration::where('user_id', $this->id)
                                          ->where('available_integration_id', $availableIntegration->id)
                                          ->first();

        if (!$userIntegration) {
            return null;
        }

        return $userIntegration->schema->discord_webhook;
    } catch (\Exception $e) { }

    return null;
}

Retry sending a notification if you're being rate limited by Discord

Hi, all,

First of all great package, thank you!

I'm trying to channel all notifications in my application to our staff discord's channel. Sometimes we send many notifications at once to various text channels we end up being rate limited.

I saw a pull request that returns the underlying GuzzleHttp exception inCouldNotSendNotification. Our notifications are queued and sent "asynchronously", so I was thinking of releasing the job again after the seconds spcified in the response by Discord.

This is my code in theory, because I don't know how to test it without making real requests to Discord (test it in ci/cd pipelines):

public function failed(Exception $exception)
{
    if ($exception instanceof CouldNotSendNotification) {
        if ($exception->getCode() === 429) {
            $json = json_decode($exception->getPrevious()->getResponse());
            $this->release($json->retry_after);
        }
    }
}

Could you please advise on how to proceed?

Thank you,
Ivanka

HTTP error: 403: Cannot send messages to this user

I'm getting the following message,

Line 24 in [...]/vendor/laravel-notification-channels/discord/src/Exceptions/CouldNotSendNotification.php- Discord responded with an HTTP error: 403: Cannot send messages to this user

But I am unable to figure out how to catch this exception and handle it accordingly. The issue here is that the Discord bot no longer has any channels in common with that particular user, so its unable to send that PM - which makes sense.

How can I catch these exceptions from inside the Notification itself? It's sent to a few different users, not individually, so catching the Notification::send() method is not an option.

Send embed message with image

Hi,
I need some help. I did not find example in readme file.
I would like to send embed message which includes images. please, could anybody post correct syntax of adding image to message.
Thank you!

README needs improving.

The Usage of the package in the read is missing many of the basic. A simple way of just sending a notification to a channel will go a long way if you add it. Thank you

usage with discord webhooks?

title is self-explanatory but i'm gonna ask it again. can i use this package with discord webhooks? (seems like i can't) i want to able it for my users to write down a discord url and receive messages.

Driver not supported

I followed the installation procedure but with my first try sending a notification i get the following error:

InvalidArgumentException in Manager.php line 90: Driver [App\Notifications\DiscordChannel] not supported.

Laravel doesn't identify the bot

I have created a discord app and a bot. I invited the bot to my discord server and pasted the token in config/services.php.

'discord' => [
    'token' => 'BOT_TOKEN',
],

But when I run the artisan command php artisan discord:setup to identify the bot I get the following error message.

image

Discord responded with an HTTP error: 403: Missing Access

I want to send notification to discord channel from laravel project:

  1. I have added

use Notifiable to my model
public function routeNotificationForDiscord() { return '123123123123123123123'; //real channel id } as well

  1. also I have added 'discord' => [ 'token' => env('DISCORD_BOT_TOKEN'), ], to services.php and added DISCORD_BOT_TOKEN=gjadkgja1361.djga163.kjg13613djg to my .env file

And when i try to do Favorite::find(1)->notify(new AddedToFavoritesDiscordMessage()); i receive Discord responded with an HTTP error: 403: Missing Access

/vendor/laravel-notification-channels/discord/src/Discord.php", line: 93, function: "serviceRespondedWithAnHttpError", โ€ฆ }

Installing via Composer

I've spent a while trying to get this installed, have not been able to find any problems related to this, and have reviewed my server configuration and reviewed PHP versions(PHP 7.0.20)
My Laravel Version is 5.4.33.
[root] # php artisan --version Laravel Framework 5.4.33 [root] #

The Composer Error Output

Using version ^1.0 for laravel-notification-channels/discord
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel-notification-channels/discord ^1.0 -> satisfiable by laravel-notification-channels/discord[v1.0.0].
    - Conclusion: remove laravel/framework v5.4.33
    - Conclusion: don't install laravel/framework v5.4.33
    - laravel-notification-channels/discord v1.0.0 requires illuminate/queue 5.1.*|5.2.*|5.3.* -> satisfiable by illuminate/queue[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4].
    - don't install illuminate/queue v5.1.1|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.13|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.16|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.2|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.20|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.22|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.25|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.28|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.30|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.31|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.41|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.6|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.1.8|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.0|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.19|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.21|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.24|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.25|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.26|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.27|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.28|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.31|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.32|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.37|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.43|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.45|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.6|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.2.7|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.3.0|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.3.16|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.3.23|don't install laravel/framework v5.4.33
    - don't install illuminate/queue v5.3.4|don't install laravel/framework v5.4.33
    - Installation request for laravel/framework (locked at v5.4.33, required as 5.4.*) -> satisfiable by laravel/framework[v5.4.33].


Installation failed, reverting ./composer.json to its original content.

Thanks, sorry if this is something obvious.

DiscordPHP will not run on a webserver. Please use PHP CLI to run a DiscordPHP bot.

I add step by step notification and after enter to page (page test notification) i see that error. Command in CLI i run

 php artisan discord:setup

 Is the bot already added to your server? (yes/no) [no]:
 > 

 What is your Discord app client ID?:
 > *********************

Add the bot to your server by visiting this link: https://discord.com/oauth2/authorize?&client_id=******************&scope=bot&permissions=0

 Continue? (yes/no) [yes]:
 > yes

Attempting to identify the bot with Discord's websocket gateway...
Connecting to 'wss://gateway.discord.gg'...
Your bot has been identified by Discord and can now send API requests!

Crush on line
app(Discord::class)->getPrivateChannel($discordId); //$discordId = discord_user_id

Discord responded with an error while trying to identify the bot:

Not works

Attempting to identify the bot with Discord's websocket gateway...
Connecting to 'wss://gateway.discord.gg'...
Discord responded with an error while trying to identify the bot: {"t":null,"s":null,"op":10,"d":{"heartbeat_interval":41250,"_trace":["gateway-prd-main-3q62"]}}

NotificationChannels\Discord\Exceptions\CouldNotSendNotification with message 'Discord responded with an HTTP error: 400'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.