Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: persist other features when changing the community feature #705

Merged
merged 4 commits into from Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/705.bugfix.rst
@@ -0,0 +1 @@
Fixed an issue where it would be possible to remove other features when enabling or disabling the ``COMMUNITY`` feature for a :class:`.Guild`.
28 changes: 20 additions & 8 deletions disnake/guild.py
Expand Up @@ -1975,16 +1975,28 @@ async def edit(
fields["system_channel_flags"] = system_channel_flags.value

if community is not MISSING:
features = []
if community:
if "rules_channel_id" in fields and "public_updates_channel_id" in fields:
features.append("COMMUNITY")
# If we don't have complete feature information for the guild,
# it is possible to disable or enable other features that we didn't intend to touch.
# To enable or disable a feature, we will need to provide all of the existing features in advance.
if self.unavailable:
raise RuntimeError(
"cannot modify features of an unavailable guild due to potentially destructive results."
)
features = set(self.features)
if community is not MISSING:
if not isinstance(community, bool):
raise TypeError("community must be a bool instance")
if community:
if "rules_channel_id" in fields and "public_updates_channel_id" in fields:
features.add("COMMUNITY")
else:
raise ValueError(
"community field requires both rules_channel and public_updates_channel fields to be provided"
)
else:
raise ValueError(
"community field requires both rules_channel and public_updates_channel fields to be provided"
)
features.discard("COMMUNITY")

fields["features"] = features
fields["features"] = list(features)

if premium_progress_bar_enabled is not MISSING:
fields["premium_progress_bar_enabled"] = premium_progress_bar_enabled
Expand Down