Skip to content

Fix support for edit and delete on webhooks with thread_id #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions discord_webhook/async_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ async def edit(self) -> "httpx.Response":
if bool(self.files) is False:
patch_kwargs = {
"json": self.json,
"params": {"wait": True},
"params": self._query_params,
"timeout": self.timeout,
}
else:
self.files["payload_json"] = (None, json.dumps(self.json))
patch_kwargs = {"files": self.files, "timeout": self.timeout}
patch_kwargs = {
"files": self.files,
"timeout": self.timeout,
"params": self._query_params
}
request = partial(client.patch, url, **patch_kwargs)
response = await request()
if response.status_code in [200, 204]:
Expand Down Expand Up @@ -171,7 +175,11 @@ async def delete(self) -> "httpx.Response":
), "Webhook URL needs to be set in order to delete the webhook."
url = f"{self.url}/messages/{self.id}"
async with self.http_client as client: # type: httpx.AsyncClient
response = await client.delete(url, timeout=self.timeout)
response = await client.delete(
url,
timeout=self.timeout,
params=self._query_params
)
if response.status_code in [200, 204]:
logger.debug("Webhook deleted")
else:
Expand All @@ -181,4 +189,4 @@ async def delete(self) -> "httpx.Response":
content=response.content.decode("utf-8"),
)
)
return response
return response
18 changes: 15 additions & 3 deletions discord_webhook/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def edit(self) -> "requests.Response":
url,
json=self.json,
proxies=self.proxies,
params={"wait": True},
params=self._query_params,
timeout=self.timeout,
)
else:
Expand All @@ -492,6 +492,7 @@ def edit(self) -> "requests.Response":
url,
files=self.files,
proxies=self.proxies,
params=self._query_params,
timeout=self.timeout,
)
response = request()
Expand Down Expand Up @@ -522,14 +523,25 @@ def delete(self) -> "requests.Response":
), "Webhook URL needs to be set in order to delete the webhook."
url = f"{self.url}/messages/{self.id}"
request = partial(
requests.delete, url, proxies=self.proxies, timeout=self.timeout
requests.delete,
url,
proxies=self.proxies,
timeout=self.timeout,
params=self._query_params
)
response = request()
if response.status_code in [200, 204]:
logger.debug("Webhook deleted")
elif response.status_code == 429 and self.rate_limit_retry:
response = self.handle_rate_limit(response, request)
logger.debug("Webhook edited")
else:
logger.error(
"Webhook status code {status_code}: {content}".format(
status_code=response.status_code,
content=response.content.decode("utf-8"),
)
)
return response

@classmethod
Expand All @@ -542,4 +554,4 @@ def create_batch(cls, urls: List[str], **kwargs) -> Tuple["DiscordWebhook", ...]
"""
if "url" in kwargs:
raise TypeError("'url' can't be used as a keyword argument.")
return tuple([cls(url, **kwargs) for url in urls])
return tuple([cls(url, **kwargs) for url in urls])