Automatic webhook creation and deletion, Resolves #42

This commit is contained in:
Jeremy Zhang
2017-08-27 21:41:36 +00:00
parent 8038a1b4fc
commit 654dd3faf3
11 changed files with 225 additions and 8 deletions

View File

@ -145,6 +145,16 @@ class DiscordREST:
# Webhook
#####################
def create_webhook(self, channel_id, name, avatar=None):
_endpoint = "/channels/{channel_id}/webhooks".format(channel_id=channel_id)
payload = {
"name": name,
}
if avatar:
payload["avatar"] = avatar
r = self.request("POST", _endpoint, data=payload, json=True)
return r
def execute_webhook(self, webhook_id, webhook_token, username, avatar, content, wait=True):
_endpoint = "/webhooks/{id}/{token}".format(id=webhook_id, token=webhook_token)
if wait:
@ -155,4 +165,9 @@ class DiscordREST:
'username': username
}
r = self.request("POST", _endpoint, data=payload)
return r
def delete_webhook(self, webhook_id, webhook_token):
_endpoint = "/webhooks/{id}/{token}".format(id=webhook_id, token=webhook_token)
r = self.request("DELETE", _endpoint)
return r