Implement TextChannel.follow()

This commit is contained in:
NCPlayz
2019-10-08 20:45:44 +01:00
committed by Rapptz
parent 80702df1bc
commit dab2519a09
3 changed files with 66 additions and 1 deletions

View File

@ -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.