diff --git a/src/DiscordDriver.php b/src/DiscordDriver.php index c16ac37..858555e 100644 --- a/src/DiscordDriver.php +++ b/src/DiscordDriver.php @@ -52,6 +52,7 @@ public function __construct(array $config, Discord $client) */ public function connected() { + $this->bot_id = $this->client->user->tag; } /** @@ -88,7 +89,7 @@ public function hasMatchingEvent() */ public function getConversationAnswer(IncomingMessage $message) { - return Answer::create($this->message->content)->setMessage($message); + return Answer::create($this->message->content ?? null)->setMessage($message); } /** @@ -98,9 +99,9 @@ public function getConversationAnswer(IncomingMessage $message) */ public function getMessages() { - $messageText = $this->message->content; - $user_id = $this->message->author->id; - $channel_id = $this->message->channel->id; + $messageText = $this->message->content ?? null; + $user_id = $this->message->author->id ?? null; + $channel_id = $this->message->channel->id ?? null; $message = new IncomingMessage($messageText, $user_id, $channel_id, $this->message); $message->setIsFromBot($this->isBot()); @@ -113,7 +114,7 @@ public function getMessages() */ protected function isBot() { - return false; + return $this->message->author->bot ?? false;; } /** @@ -156,6 +157,10 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam */ public function sendPayload($payload) { + if (empty($this->message)) { + return null; + } + return $this->message->channel->sendMessage($payload['message'], false, $payload['embed']); }