Larascord dispatches its own events from the package. There is nothing to publish or register.
| Event | Dispatched when | Properties |
|---|---|---|
DiscordAccountCreated | A Discord account is inserted into larascord_accounts. | $account |
DiscordAccountUpdated | An existing Discord account is updated. | $account |
DiscordAccountLinked | A Discord account is assigned a user_id. | $account, $user |
DiscordAccountUnlinked | A Discord account is deleted. | $account |
UserAuthenticated | The callback completes a login. | $account, $user |
The events are in the Jakyeru\Larascord\Events namespace. $account is a Jakyeru\Larascord\Models\DiscordAccount and $user is an Illuminate\Contracts\Auth\Authenticatable.
Listening
Create a listener
php artisan make:listener WelcomeNewUserType hint the event
Laravel discovers the listener from the type hint of the handle method.
app/Listeners/WelcomeNewUser.php
<?php
namespace App\Listeners;
use Illuminate\Support\Facades\Log;
use Jakyeru\Larascord\Events\DiscordAccountCreated;
class WelcomeNewUser
{
public function handle(DiscordAccountCreated $event): void
{
Log::info('Welcome ' . $event->account->tag);
}
}Example: adding the user to a guild
app/Listeners/AddUserToGuild.php
<?php
namespace App\Listeners;
use Jakyeru\Larascord\Events\UserAuthenticated;
class AddUserToGuild
{
public function handle(UserAuthenticated $event): void
{
$event->account->joinGuild('81384788765712384');
}
}Example: rejecting a banned user
app/Listeners/BlockBannedUsers.php
<?php
namespace App\Listeners;
use Illuminate\Support\Facades\Auth;
use Jakyeru\Larascord\Events\UserAuthenticated;
class BlockBannedUsers
{
public function handle(UserAuthenticated $event): void
{
if ($event->user->is_banned) {
Auth::logout();
}
}
}