Skip to content

Commit

Permalink
feat: improve guild creation, add new guild builder (#578)
Browse files Browse the repository at this point in the history
Adds support for the previously missing parameters on the [create guild
endpoint](https://discord.com/developers/docs/resources/guild#create-guild)
(literally all of them except `name` + `icon`), adding a builder class
to abstract away most of the placeholder ID handling.

Co-authored-by: arl <[email protected]>
  • Loading branch information
shiftinv and onerandomusername authored Jan 12, 2023
1 parent 034f881 commit 5810c1d
Show file tree
Hide file tree
Showing 8 changed files with 605 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog/578.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :class:`GuildBuilder` and :func:`Client.guild_builder` for full coverage of the guild creation endpoint.
31 changes: 27 additions & 4 deletions disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
)
from .flags import ApplicationFlags, Intents, MemberCacheFlags
from .gateway import DiscordWebSocket, ReconnectWebSocket
from .guild import Guild
from .guild import Guild, GuildBuilder
from .guild_preview import GuildPreview
from .http import HTTPClient
from .i18n import LocalizationProtocol, LocalizationStore
Expand Down Expand Up @@ -1883,7 +1883,9 @@ async def create_guild(
Creates a :class:`.Guild`.
Bot accounts in more than 10 guilds are not allowed to create guilds.
See :func:`guild_builder` for a more comprehensive alternative.
Bot accounts in 10 or more guilds are not allowed to create guilds.
.. versionchanged:: 2.5
Removed the ``region`` parameter.
Expand Down Expand Up @@ -1921,8 +1923,7 @@ async def create_guild(
Returns
-------
:class:`.Guild`
The created guild. This is not the same guild that is
added to cache.
The created guild. This is not the same guild that is added to cache.
"""
if icon is not MISSING:
icon_base64 = await utils._assetbytes_to_base64_data(icon)
Expand All @@ -1935,6 +1936,28 @@ async def create_guild(
data = await self.http.create_guild(name, icon_base64)
return Guild(data=data, state=self._connection)

def guild_builder(self, name: str) -> GuildBuilder:
"""Creates a builder object that can be used to create more complex guilds.
This is a more comprehensive alternative to :func:`create_guild`.
See :class:`.GuildBuilder` for details and examples.
Bot accounts in 10 or more guilds are not allowed to create guilds.
.. versionadded:: 2.8
Parameters
----------
name: :class:`str`
The name of the guild.
Returns
-------
:class:`.GuildBuilder`
The guild builder object for configuring and creating a new guild.
"""
return GuildBuilder(name=name, state=self._connection)

async def fetch_stage_instance(self, channel_id: int, /) -> StageInstance:
"""|coro|
Expand Down
Loading

0 comments on commit 5810c1d

Please sign in to comment.