Adjust examples to reflect the new top-level exposure of classes and enums, such as `Client`, `Permissions`, `Embed`, and `Button`, making imports simpler.
1.1 KiB
1.1 KiB
Working with Webhooks
The HTTPClient
includes helper methods for creating, editing and deleting Discord webhooks.
Create a webhook
from disagreement import HTTPClient
http = HTTPClient(token="TOKEN")
payload = {"name": "My Webhook"}
webhook = await http.create_webhook("123", payload)
Edit a webhook
await http.edit_webhook("456", {"name": "Renamed"})
Delete a webhook
await http.delete_webhook("456")
The methods now return a Webhook
object directly:
from disagreement import Webhook
print(webhook.id, webhook.name)
Create a Webhook from a URL
You can construct a Webhook
object from an existing webhook URL without any API calls:
from disagreement import Webhook
webhook = Webhook.from_url("https://discord.com/api/webhooks/123/token")
print(webhook.id, webhook.token)
Send a message through a Webhook
Once you have a Webhook
instance bound to a :class:Client
, you can send messages using it:
webhook = await client.create_webhook("123", {"name": "Bot Webhook"})
await webhook.send(content="Hello from my webhook!", username="Bot")