From dab2519a09bb64d335a80423fb1d522e46a1ee5c Mon Sep 17 00:00:00 2001 From: NCPlayz Date: Tue, 8 Oct 2019 20:45:44 +0100 Subject: Implement `TextChannel.follow()` --- discord/channel.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'discord/channel.py') 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. -- cgit v1.2.3