aboutsummaryrefslogtreecommitdiff
path: root/discord/webhook.py
diff options
context:
space:
mode:
authorNCPlayz <[email protected]>2019-11-23 12:44:50 +0000
committerRapptz <[email protected]>2019-11-26 05:16:53 -0500
commitf554819506356b9c78fd6dbf07a88eadf9dd4693 (patch)
tree16602ce5c26dba39533c0721670f78250a2a0870 /discord/webhook.py
parentFix typo in help.py docs (diff)
downloaddiscord.py-f554819506356b9c78fd6dbf07a88eadf9dd4693.tar.xz
discord.py-f554819506356b9c78fd6dbf07a88eadf9dd4693.zip
Implement `Webhook.type`
Diffstat (limited to 'discord/webhook.py')
-rw-r--r--discord/webhook.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/discord/webhook.py b/discord/webhook.py
index 971a7ad6..513138a5 100644
--- a/discord/webhook.py
+++ b/discord/webhook.py
@@ -33,6 +33,7 @@ import aiohttp
from . import utils
from .errors import InvalidArgument, HTTPException, Forbidden, NotFound
+from .enums import try_enum, WebhookType
from .user import BaseUser, User
from .asset import Asset
@@ -401,6 +402,8 @@ class Webhook:
------------
id: :class:`int`
The webhook's ID
+ type: :class:`WebhookType`
+ The type of the webhook.
token: Optional[:class:`str`]
The authentication token of the webhook. If this is ``None``
then the webhook cannot be used to make requests.
@@ -417,11 +420,12 @@ class Webhook:
The default avatar of the webhook.
"""
- __slots__ = ('id', 'guild_id', 'channel_id', 'user', 'name', 'avatar',
- 'token', '_state', '_adapter')
+ __slots__ = ('id', 'type', 'guild_id', 'channel_id', 'user', 'name',
+ 'avatar', 'token', '_state', '_adapter')
def __init__(self, data, *, adapter, state=None):
self.id = int(data['id'])
+ self.type = try_enum(WebhookType, int(data['type']))
self.channel_id = utils._get_as_snowflake(data, 'channel_id')
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
self.name = data.get('name')
@@ -470,6 +474,7 @@ class Webhook:
data = {
'id': id,
+ 'type': 1,
'token': token
}
@@ -497,13 +502,16 @@ class Webhook:
m = re.search(r'discordapp.com/api/webhooks/(?P<id>[0-9]{17,21})/(?P<token>[A-Za-z0-9\.\-\_]{60,68})', url)
if m is None:
raise InvalidArgument('Invalid webhook URL given.')
- return cls(m.groupdict(), adapter=adapter)
+ data = m.groupdict()
+ data['type'] = 1
+ return cls(data, adapter=adapter)
@classmethod
def _as_follower(cls, data, *, channel, user):
name = "{} #{}".format(channel.guild, channel)
feed = {
'id': data['webhook_id'],
+ 'type': 2,
'name': name,
'channel_id': channel.id,
'guild_id': channel.guild.id,