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

feat: Add Guild.delete_auto_moderation_rule #2153

Merged
merged 21 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ These changes are available on the `master` branch, but have not yet been releas

### Added

- Added function `delete_auto_moderation_rule`.
llamaair marked this conversation as resolved.
Show resolved Hide resolved
([#2153]https://github.com/Pycord-Development/pycord/pull/2153)
llamaair marked this conversation as resolved.
Show resolved Hide resolved
- Added possibility to start bot via async context manager.
([#1801](https://github.com/Pycord-Development/pycord/pull/1801))
- Change default for all `name_localizations` & `description_localizations` attributes
Expand Down
55 changes: 55 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -3816,3 +3816,58 @@ async def create_auto_moderation_rule(
self.id, payload, reason=reason
)
return AutoModRule(state=self._state, data=data)

async def delete_auto_moderation_rule(
self,
*,
id: int | None = None,
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
name: str | None = None,
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
reason: str | None = None,
) -> AutoModRule:
"""
Deletes an auto moderation rule.

Parameters
----------
id: Optional[int]
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
The ID of the auto moderation rule.
name: Optional[str]
The name of the auto moderation rule.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
reason: Optional[str]
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
The reason for deleting the rule. Shows up in the audit log.

Raises
------
ValueError
If neither 'id' nor 'name' is provided.
ValueError
If both 'id' and 'name' are provided.
ValueError
If no auto moderation rule is found with the given name.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
HTTPException
Deleting the auto moderation rule failed.
Forbidden
You do not have the Manage Guild permission.
"""

if not id and not name:
raise ValueError("Either 'id' or 'name' must be provided.")

if id and name:
raise ValueError("Only one of 'id' or 'name' can be provided.")

if name:
# Get all auto moderation rules
rules_response = await self._state.http.get_auto_moderation_rules(self.id)
rules = rules_response

# Find the rule by name
matching_rules = [rule for rule in rules if rule["name"] == name]
if not matching_rules:
raise ValueError(f"No auto moderation rule found with name '{name}'.")
id = matching_rules[0]["id"]

Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
data = await self._state.http.delete_auto_moderation_rule(
self.id, id, reason=reason
)
return
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved