mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-08 10:53:10 +00:00
Implement TextChannel.follow()
This commit is contained in:
@ -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.
|
||||
|
||||
|
Reference in New Issue
Block a user