From 42e5e09ae450247bbcf83cfe1eec49a49e399b2c Mon Sep 17 00:00:00 2001 From: kotyara <62548070+kotyaralih@users.noreply.github.com> Date: Mon, 9 May 2022 13:41:35 +0000 Subject: [PATCH] Fix lag while sending a message to discord --- src/PocketMinecraftServer.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index d1c61f7f..622b4817 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -716,16 +716,14 @@ class PocketMinecraftServer{ if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){ $url = $this->extraprops->get("discord-webhook-url"); $name = $this->extraprops->get("discord-bot-name"); - $headers = [ 'Content-Type: application/json; charset=utf-8' ]; - $POST = [ 'username' => $name, 'content' => str_replace("@", "", $msg)]; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($POST)); - $response = curl_exec($ch); + $this->asyncOperation(ASYNC_CURL_POST, array( + "url" => $url, + "data" => array( + "username" => $name, + "content" => str_replace("@", "", $msg) + ), + ), NULL); + } } } \ No newline at end of file