url = Hajeebtok::$Config->GetByDotKey("Instance.DiscordWebhookURL"); else $this->url = $url; } public function SetAvatarURL(string $avatar_url): void { $this->avatar_url = $avatar_url; } public function SetUsername(string $username): void { $this->username = $username; } public function AddEmbed(array $embed): void { $this->embeds[] = $embed; } public function SetContent(string $content): void { $this->content = $content; } public function Send(): void { $data = []; if(!empty($this->username)) $data["username"] = $this->username; if(!empty($this->avatar_url)) $data["avatar_url"] = $this->avatar_url; if(!empty($this->embeds)) $data["embeds"] = $this->embeds; if(!empty($this->content)) $data["content"] = $this->content; if(empty($this->embeds) && empty($this->content)) throw new InvalidWebhookMessageException(0, 400); $this->PostRequest($this->url, $data); } public static function postRequest(string $url, array $payload): string { $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($payload)), ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($error) { throw new \Exception("Curl error: " . $error); } return $response; } }