PHP code example of famouswolluf / laravel-discord
1. Go to this page and download the library: Download famouswolluf/laravel-discord library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// ...
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}**!");
}
}
// ...
use NotificationChannels\Discord\DiscordChannel;
use NotificationChannels\Discord\DiscordMessage;
class SendDiscordEmbedMessage extends Notification
{
private $channelId;
private $messageData;
private $reaction;
public function __construct($channelId = null, $messageContent = null, $reaction = null)
{
$this->channelId = $channelId;
$this->messageData = $messageContent;
$this->reaction = $reaction;
}
public function getChannelId()
{
return $this->channelId;
}
public function via($notifiable)
{
return [DiscordChannel::class];
}
public function toDiscord($notifiable)
{
$discordMessage = DiscordMessage::create()
->embed([
'title' => $this->messageData['title'],
'description' => $this->messageData['message'],
'color' => $this->messageData['color'],
'image' => [
'url' => $this->messageData['image']
],
]);
if ($this->reaction) {
$discordMessage->reaction($this->reaction);
}
return $discordMessage;
}
}
shell
php artisan discord:setup
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.