'Delete Webhooks Discord.py
In discord.py, I know you can create webhooks with:
message.channel.create_webhook(name = 'something')
But I don't know if there is an option to delete them. Is this possible? Thanks
Solution 1:[1]
AxelSparrow's method is definitely cleaner, but there is a built-in method of deleting them via webhook.delete(), though this might be a bit 'scuffed' since you'd have to use a for loop if you only have your webhook's name. In the code snippet below, I will provide two methods you can use.
# Method 1: Directly using the information from creating the webhook
hook = message.channel.create_webhook(name = 'something') # create a variable
# await hook.send("test")
await hook.delete() # then delete based on variable
# Method 2: Only use this if you don't have the webhook's other information
# get all the webhooks in a channel ??
channel_webhooks = await message.channel.webhooks()
for webhook in channel_webhooks: # iterate through the webhooks
if webhook.name == "something":
await webhook.delete()
break
Do feel free to view the class discord.Webhook documentation if you require further information or understanding.
Solution 2:[2]
There is no built-in method to do this, you will need to send an http request manually.
(EDIT - It appears I was wrong: as shown in Bagle's answer, there is indeed a built in method to delete webhooks. However, this method still works and is a little easier on the eyes.)
Something like:
await ctx.bot.http.request(Route('DELETE', '/webhooks/{webhook_id}', webhook_id=webhook_id))
You may need to adjust this to work in your implementation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bagle |
| Solution 2 |
