Implement WelcomeScreen

This commit is contained in:
Nadir Chowdhury
2022-05-22 02:26:06 +01:00
committed by GitHub
parent 2bb7ed2092
commit e2d0193531
5 changed files with 320 additions and 0 deletions

View File

@@ -86,6 +86,7 @@ from .sticker import GuildSticker
from .file import File
from .audit_logs import AuditLogEntry
from .object import OLDEST_OBJECT, Object
from .welcome_screen import WelcomeScreen, WelcomeChannel
__all__ = (
@@ -3137,6 +3138,77 @@ class Guild(Hashable):
return roles
async def welcome_screen(self) -> WelcomeScreen:
"""|coro|
Returns the guild's welcome screen.
The guild must have ``COMMUNITY`` in :attr:`~Guild.features`.
You must have the :attr:`~Permissions.manage_guild` permission to use
this as well.
.. versionadded:: 2.0
Raises
-------
Forbidden
You do not have the proper permissions to get this.
HTTPException
Retrieving the welcome screen failed.
Returns
--------
:class:`WelcomeScreen`
The welcome screen.
"""
data = await self._state.http.get_welcome_screen(self.id)
return WelcomeScreen(data=data, guild=self)
async def edit_welcome_screen(
self,
*,
description: str = MISSING,
welcome_channels: List[WelcomeChannel] = MISSING,
enabled: bool = MISSING,
reason: Optional[str] = None,
) -> WelcomeScreen:
"""|coro|
A shorthand method of :attr:`WelcomeScreen.edit` without needing
to fetch the welcome screen beforehand.
The guild must have ``COMMUNITY`` in :attr:`~Guild.features`.
You must have the :attr:`~Permissions.manage_guild` permission to use
this as well.
.. versionadded:: 2.0
Returns
--------
:class:`WelcomeScreen`
The edited welcome screen.
"""
fields = {}
if welcome_channels is not MISSING:
welcome_channels_serialised = []
for wc in welcome_channels:
if not isinstance(wc, WelcomeChannel):
raise TypeError('welcome_channels parameter must be a list of WelcomeChannel')
welcome_channels_serialised.append(wc.to_dict())
fields['welcome_channels'] = welcome_channels_serialised
if description is not MISSING:
fields['description'] = description
if enabled is not MISSING:
fields['enabled'] = enabled
data = await self._state.http.edit_welcome_screen(self.id, reason=reason, **fields)
return WelcomeScreen(data=data, guild=self)
async def kick(self, user: Snowflake, *, reason: Optional[str] = None) -> None:
"""|coro|