aboutsummaryrefslogtreecommitdiff
path: root/discord/channel.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-08-21 01:54:33 -0400
committerRapptz <[email protected]>2017-08-21 01:57:07 -0400
commit37b0fdb898a0f242f68d30abb6c58bd1a15a6524 (patch)
treebd752d8748bfb7aa4304b55183d8544f9d14886f /discord/channel.py
parentUse time.monotonic instead of time.time for heartbeat code. (diff)
downloaddiscord.py-37b0fdb898a0f242f68d30abb6c58bd1a15a6524.tar.xz
discord.py-37b0fdb898a0f242f68d30abb6c58bd1a15a6524.zip
Add webhook support.
Allows for usage of either `requests` and `aiohttp` when used in "Standalone" mode. Fixes #704
Diffstat (limited to 'discord/channel.py')
-rw-r--r--discord/channel.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/discord/channel.py b/discord/channel.py
index 946ed3bc..d81ad273 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -28,6 +28,7 @@ from .enums import ChannelType, try_enum
from .mixins import Hashable
from . import utils
from .errors import ClientException, NoMoreItems
+from .webhook import Webhook
import discord.abc
@@ -321,6 +322,66 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
count += 1
ret.append(msg)
+ @asyncio.coroutine
+ def webhooks(self):
+ """|coro|
+
+ Gets the list of webhooks from this channel.
+
+ Requires :attr:`~.Permissions.manage_webhooks` permissions.
+
+ Raises
+ -------
+ Forbidden
+ You don't have permissions to get the webhooks.
+
+ Returns
+ --------
+ List[:class:`Webhook`]
+ The webhooks for this channel.
+ """
+
+ data = yield from self._state.http.channel_webhooks(self.id)
+ return [Webhook.from_state(d, state=self._state) for d in data]
+
+ @asyncio.coroutine
+ def create_webhook(self, *, name=None, avatar=None):
+ """|coro|
+
+ Creates a webhook for this channel.
+
+ Requires :attr:`~.Permissions.manage_webhooks` permissions.
+
+ Parameters
+ -------------
+ name: Optional[str]
+ The webhook's name.
+ avatar: Optional[bytes]
+ A *bytes-like* object representing the webhook's default avatar.
+ This operates similarly to :meth:`~ClientUser.edit`.
+
+ Raises
+ -------
+ HTTPException
+ Creating the webhook failed.
+ Forbidden
+ You do not have permissions to create a webhook.
+
+ Returns
+ --------
+ :class:`Webhook`
+ The created webhook.
+ """
+
+ if avatar is not None:
+ avatar = utils._bytes_to_base64_data(avatar)
+
+ if name is not None:
+ name = str(name)
+
+ data = yield from self._state.http.create_webhook(self.id, name=name, avatar=avatar)
+ return Webhook.from_state(data, state=self._state)
+
class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
"""Represents a Discord guild voice channel.