Skip to content

Conversation

DA-344
Copy link
Contributor

@DA-344 DA-344 commented Nov 29, 2024

Summary

This PR adds a new guild builder to allow users to better customize a guild before creating it (see POST /guilds)

Current implementation changes the create_guild logic but it is going to be changed to a new method called build_guild.

I will try to add all the available parameters to create_guild in a understandable way.

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@Paillat-dev
Copy link
Member

Paillat-dev commented Nov 29, 2024

As mentioned by @NeloBlivion too, the builder feature does not in my opinion too belong to the core

ok yeah my previous opinion stays the same, create_guild should retain existing behavior while supporting the new parameters, and there should be a separate Client function for using GuildBuilder

https://discord.com/channels/881207955029110855/881735314987708456/1311779043531558935

But I am happy to discuss on this.

@DA-344
Copy link
Contributor Author

DA-344 commented Nov 29, 2024

Yeah, it is mentioned on the PR message:

Current implementation changes the create_guild logic but it is going to be changed to a new method called build_guild.

def delete_guild(self, guild_id: Snowflake) -> Response[None]:
return self.request(Route("DELETE", "/guilds/{guild_id}", guild_id=guild_id))

def create_guild(self, name: str, icon: str | None) -> Response[guild.Guild]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The icon parameter is removed, was it used anywhere in the library ? Just make sure this is changed everywhere it should be. Otherwise this is fine and not considered breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The icon parameter is a key for payload so it is not required as a parameter anymore, and no, this method is only used on Client.create_guild.

failed_users: list[Snowflake]


class GuildCreate(TypedDict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GuildCreate(TypedDict):
class GuildCreatePayload(TypedDict):

Attributes
----------
code: Optional[:class:`str`]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe smth more explicit than just code ? E.g. template_code.

self.system_channel_id: int | None = None
self.system_channel_flags: SystemChannelFlags | None = None

async def _do_create(self) -> Guild:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be public, to allow devs to use it as an alternative to the __await__ approach, but maybe under another name than do_create.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on this, just calling await GuildBuilder() seems too ambiguous

category_id: Optional[:class:`int`]
The category placeholder ID this channel belongs to.
bitrate: :class:`int`
The channel bitrate.
Copy link
Member

@Paillat-dev Paillat-dev Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missindented

if afk_timeout is not MISSING:
metadata["afk_timeout"] = afk_timeout

# TODO: remove support of passing ``None`` to ``icon``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you rewrote it like this, the old code for icon was sufficient

if code is MISSING:
code = None # type: ignore

if code:
Copy link
Member

@NeloBlivion NeloBlivion Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't know if code should use GuildBuilder, considering all the new parameters would be ignored (if anything it should raise a ValueError for passing it with them), though regardless i suggest create_guild be completely detached from GuildBuilder so all of its logic can remain isolated in build_guild (though i think you've said you're planning on this, either way there's no rush)

Copy link
Member

@Paillat-dev Paillat-dev Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why type ignore ? If needed used an overload.

Copy link
Member

@Lulalaby Lulalaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this isn't in the scope for the core library. It would be a better fit as (community-)extension.

@NeloBlivion
Copy link
Member

NeloBlivion commented Nov 29, 2024

I feel like this isn't in the scope for the core library. It would be a better fit as (community-)extension.

I generally agree, but the main motivation for this PR is adding support for channels and roles in guild creation since we have no friendly way for users to make these objects from scratch, hence using this builder structure.

That being said, this approach isn't ideal because we're effectively duplicating parts of the existing role and channel classes just for the sake of a relatively niche endpoint for bots (not by fault of OP, this just wasn't considered necessary in the original design). This might benefit from being held off until we have more widely applicable objects (e.g. Partial objects where users can assign any valid attributes beyond just ID for any valid model, or maybe in 3.0 we could let users arbitrarily instantiate Discord Models)

@Lulalaby
Copy link
Member

Lulalaby commented Nov 29, 2024

I generally agree, but the main motivation for this PR is adding support for channels and roles in guild creation since we have no friendly way for users to make these objects from scratch, hence using this builder structure.

Yeah. Since I only see it from discords side, the core is working as intended. Yeah is not friendly, but that's the api.
Also bots rarely create guilds themself and are limited.

That being said, this approach isn't ideal

Agreed

This might benefit from being held off until we have more widely applicable objects

Also agreed, I'm gonna be marking this PR on hold until further notice. It's not in the scope of 2.X releases.

@Lulalaby Lulalaby self-assigned this Nov 29, 2024
@Lulalaby Lulalaby added invalid This doesn't seem right priority: low Low Priority on hold Out Of Scope labels Nov 29, 2024
@DA-344 DA-344 closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right on hold Out Of Scope priority: low Low Priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants