aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-05 14:26:33 -0400
committerRapptz <[email protected]>2021-05-05 14:26:33 -0400
commit81004369dc2e5d357b0ae6986f22a801a20aca10 (patch)
tree41353e4fceac59dbbedfb8e3da29ed76e3a1bf17
parentAdd Permissions.manage_events (diff)
downloaddiscord.py-81004369dc2e5d357b0ae6986f22a801a20aca10.tar.xz
discord.py-81004369dc2e5d357b0ae6986f22a801a20aca10.zip
Add Guild.fetch_channel
-rw-r--r--discord/guild.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/discord/guild.py b/discord/guild.py
index 6c0b0901..4f1c8cab 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -1401,6 +1401,51 @@ class Guild(Hashable):
reason=data['reason']
)
+ async def fetch_channel(self, channel_id: int, /) -> abc.GuildChannel:
+ """|coro|
+
+ Retrieves a :class:`.abc.GuildChannel` with the specified ID.
+
+ .. note::
+
+ This method is an API call. For general usage, consider :meth:`get_channel` instead.
+
+ .. versionadded:: 2.0
+
+ Raises
+ -------
+ :exc:`.InvalidData`
+ An unknown channel type was received from Discord
+ or the guild the channel belongs to is not the same
+ as the one in this object points to.
+ :exc:`.HTTPException`
+ Retrieving the channel failed.
+ :exc:`.NotFound`
+ Invalid Channel ID.
+ :exc:`.Forbidden`
+ You do not have permission to fetch this channel.
+
+ Returns
+ --------
+ :class:`.abc.GuildChannel`
+ The channel from the ID.
+ """
+ data = await self._state.http.get_channel(channel_id)
+
+ factory, ch_type = _channel_factory(data['type'])
+ if factory is None:
+ raise InvalidData('Unknown channel type {type} for channel ID {id}.'.format_map(data))
+
+ if ch_type in (ChannelType.group, ChannelType.private):
+ raise InvalidData('Channel ID resolved to a private channel')
+
+ guild_id = int(data['guild_id'])
+ if self.id != guild_id:
+ raise InvalidData('Guild ID resolved to a different guild')
+
+ channel: abc.GuildChannel = factory(guild=self, state=self._state, data=data) # type: ignore
+ return channel
+
async def bans(self):
"""|coro|