Implement StageInstance

This commit is contained in:
Nadir Chowdhury
2021-05-30 18:51:52 +01:00
committed by GitHub
parent 90a28d48d5
commit 9f98a9a87f
10 changed files with 502 additions and 15 deletions

View File

@ -29,7 +29,7 @@ import logging
import signal
import sys
import traceback
from typing import Any, List, Optional, TYPE_CHECKING, Union
from typing import Any, Generator, List, Optional, TYPE_CHECKING, TypeVar, Union
import aiohttp
@ -56,6 +56,7 @@ from .webhook import Webhook
from .iterators import GuildIterator
from .appinfo import AppInfo
from .ui.view import View
from .stage_instance import StageInstance
__all__ = (
'Client',
@ -693,6 +694,28 @@ class Client:
"""
return self._connection.get_channel(id)
def get_stage_instance(self, id) -> Optional[StageInstance]:
"""Returns a stage instance with the given stage channel ID.
.. versionadded:: 2.0
Parameters
-----------
id: :class:`int`
The ID to search for.
Returns
--------
Optional[:class:`StageInstance`]
The returns stage instance of ``None`` if not found.
"""
from .channel import StageChannel
channel = self._connection.get_channel(id)
if isinstance(channel, StageChannel):
return channel.instance
def get_guild(self, id):
"""Returns a guild with the given ID.
@ -1136,6 +1159,34 @@ class Client:
data = await self.http.create_guild(name, region_value, icon)
return Guild(data=data, state=self._connection)
async def fetch_stage_instance(self, channel_id: int) -> StageInstance:
"""|coro|
Gets a :class:`StageInstance` for a stage channel id.
.. versionadded:: 2.0
Parameters
-----------
channel_id: :class:`int`
The stage channel ID.
Raises
-------
:exc:`.NotFound`
The stage instance or channel could not be found.
:exc:`.HTTPException`
Getting the stage instance failed.
Returns
--------
:class:`StageInstance`
The stage instance from the stage channel ID.
"""
data = await self.http.get_stage_instance(channel_id)
guild = self.get_guild(int(data['guild_id']))
return StageInstance(guild=guild, state=self._connection, data=data) # type: ignore
# Invite management
async def fetch_invite(self, url: Union[Invite, str], *, with_counts: bool = True, with_expiration: bool = True) -> Invite:
@ -1261,7 +1312,7 @@ class Client:
async def fetch_user(self, user_id):
"""|coro|
Retrieves a :class:`~discord.User` based on their ID.
Retrieves a :class:`~discord.User` based on their ID.
You do not have to share any guilds with the user to get this information,
however many operations do require that you do.