diff options
| author | NCPlayz <[email protected]> | 2019-10-08 20:45:44 +0100 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-11-15 04:23:15 -0500 |
| commit | dab2519a09bb64d335a80423fb1d522e46a1ee5c (patch) | |
| tree | 4b60027d4b57f4824c8d23b940cc55d5e7436788 /discord/channel.py | |
| parent | [docs] add new FAQ entries (diff) | |
| download | discord.py-dab2519a09bb64d335a80423fb1d522e46a1ee5c.tar.xz discord.py-dab2519a09bb64d335a80423fb1d522e46a1ee5c.zip | |
Implement `TextChannel.follow()`
Diffstat (limited to 'discord/channel.py')
| -rw-r--r-- | discord/channel.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/discord/channel.py b/discord/channel.py index de938142..f066e620 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -33,7 +33,7 @@ from .enums import ChannelType, try_enum from .mixins import Hashable from . import utils from .asset import Asset -from .errors import ClientException, NoMoreItems +from .errors import ClientException, NoMoreItems, InvalidArgument from .webhook import Webhook __all__ = ( @@ -455,6 +455,46 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): data = await self._state.http.create_webhook(self.id, name=str(name), avatar=avatar, reason=reason) return Webhook.from_state(data, state=self._state) + async def follow(self, *, destination): + """ + Follows a channel using a webhook. + + Only news channels can be followed. + + .. note:: + + The webhook returned will not provide a token to do webhook + actions, as Discord does not provide it. + + .. versionadded:: 1.3.0 + + Parameters + ----------- + destination: :class:`TextChannel` + The channel you would like to follow from. + + Raises + ------- + HTTPException + Following the channel failed. + Forbidden + You do not have the permissions to create a webhook. + + Returns + -------- + :class:`Webhook` + The created webhook. + """ + + if not self.is_news(): + raise ClientException('The channel must be a news channel.') + + if not isinstance(destination, TextChannel): + raise InvalidArgument('Expected TextChannel received {0.__name__}'.format(type(destination))) + + data = await self._state.http.follow_webhook(self.id, webhook_channel_id=destination.id) + return Webhook._as_follower(data, channel=destination, user=self._state.user) + class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable): """Represents a Discord guild voice channel. |