-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
By adding this function to DiscordWebhook.php gives the ability to edit existing messages
public function patch(): bool
{
try {
$ch = curl_init($this->webhookUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->message->toJson());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($this->message->toJson())
));
$response = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($responseCode >= 200 && $responseCode < 300) {
return true;
} else {
$decodedResponse = json_decode($response, true);
throw new InvalidResponseException($decodedResponse["message"] ?? "", $responseCode);
}
} catch (\Exception $e) {
echo $e->getMessage();
return false;
}
}
Usage example:
if ($postedID == '') {
$webhook->setWebhookUrl($WebHookUrl);
$webhook->send();
} else {
$webhook->setWebhookUrl($WebHookUrl . "/messages/" . $postedID);
$webhook->patch();
}
Metadata
Metadata
Assignees
Labels
No labels