@@ -652,3 +652,140 @@ async def get_guild_auditlog(
652652 return await self ._req .request (
653653 Route ("GET" , f"/guilds/{ guild_id } /audit-logs" ), params = payload
654654 )
655+
656+ async def list_auto_moderation_rules (self , guild_id : int ) -> List [dict ]:
657+ """
658+ Returns a list of all AutoMod rules in a guild.
659+ :poram guild_id: Guild ID snowflake.
660+ :return: A list of dictionaries containing the automod rules.
661+ """
662+
663+ return await self ._req .request (Route ("GET" , f"/guilds/{ guild_id } /auto-moderation/rules" ))
664+
665+ async def get_auto_moderation_rule (self , guild_id : int , rule_id : int ) -> dict :
666+ """
667+ Get a single AutoMod rule in a guild.
668+ :param guild_id: Guild ID snowflake.
669+ :param rule_id: Rule ID snowflake.
670+ :return: A dictionary containing the automod rule.
671+ """
672+
673+ return await self ._req .request (
674+ Route ("GET" , f"/guilds/{ guild_id } /auto-moderation/rules/{ rule_id } " )
675+ )
676+
677+ async def create_auto_moderation_rule (
678+ self ,
679+ guild_id : int ,
680+ name : str ,
681+ event_type : int ,
682+ trigger_type : int ,
683+ actions : List [dict ],
684+ trigger_metadata : Optional [dict ] = None ,
685+ enabled : Optional [bool ] = False ,
686+ exempt_roles : Optional [List [str ]] = None ,
687+ exempt_channels : Optional [List [str ]] = None ,
688+ reason : Optional [str ] = None ,
689+ ) -> dict :
690+ """
691+ Create a new AutoMod rule in a guild.
692+
693+ :param guild_id: Guild ID snowflake.
694+ :param name: The name of the new rule.
695+ :param event_type: The event type of the new rule.
696+ :param trigger_type: The trigger type of the new rule.
697+ :param trigger_metadata: The trigger metadata payload representation. This can be omitted based on the trigger type.
698+ :param actions: The actions that will execute when the rule is triggered.
699+ :param enabled: Whether the rule will be enabled upon creation. False by default.
700+ :param exempt_roles: The role IDs that are whitelisted by the rule, if given. The maximum is 20.
701+ :param exempt_channels: The channel IDs that are whitelisted by the rule, if given. The maximum is 20
702+ :param reason: Reason to send to audit log, if any.
703+ :return: A dictionary containing the new automod rule.
704+ """
705+
706+ params = {
707+ "name" : name ,
708+ "event_type" : event_type ,
709+ "trigger_type" : trigger_type ,
710+ "actions" : actions ,
711+ "enabled" : enabled ,
712+ }
713+ if trigger_metadata :
714+ params ["trigger_metadata" ] = trigger_metadata
715+ if exempt_roles :
716+ params ["exempt_roles" ] = exempt_roles
717+ if exempt_channels :
718+ params ["exempt_channels" ] = exempt_channels
719+
720+ return await self ._req .request (
721+ Route (
722+ "POST" , f"/guilds/{ guild_id } /auto-moderation/rules/" , params = params , reason = reason
723+ )
724+ )
725+
726+ async def modify_auto_moderation_rule (
727+ self ,
728+ guild_id : int ,
729+ rule_id : int ,
730+ name : Optional [str ] = None ,
731+ event_type : Optional [int ] = None ,
732+ trigger_metadata : Optional [dict ] = None ,
733+ actions : Optional [List [dict ]] = None ,
734+ enabled : Optional [bool ] = None ,
735+ exempt_roles : Optional [List [str ]] = None ,
736+ exempt_channels : Optional [List [str ]] = None ,
737+ reason : Optional [str ] = None ,
738+ ) -> dict :
739+ """
740+ Modify an existing AutoMod rule in a guild.
741+
742+ .. note ::
743+ All parameters besides guild and rule ID are optional.
744+
745+ :param guild_id: Guild ID snowflake.
746+ :param rule_id: Rule ID snowflake.
747+ :param name: The new name of the rule.
748+ :param event_type: The new event type of the rule.
749+ :param trigger_metadata: The new trigger metadata payload representation. This can be omitted based on the trigger type.
750+ :param actions: The new actions that will execute when the rule is triggered.
751+ :param enabled: Whether the rule will be enabled upon creation.
752+ :param exempt_roles: The role IDs that are whitelisted by the rule, if given. The maximum is 20.
753+ :param exempt_channels: The channel IDs that are whitelisted by the rule, if given. The maximum is 20
754+ :param reason: Reason to send to audit log, if any.
755+ :return: A dictionary containing the updated automod rule.
756+ """
757+ payload = {}
758+ if name :
759+ payload ["name" ] = name
760+ if event_type :
761+ payload ["event_type" ] = event_type
762+ if trigger_metadata :
763+ payload ["trigger_metadata" ] = trigger_metadata
764+ if actions :
765+ payload ["actions" ] = actions
766+ if enabled :
767+ payload ["enabled" ] = enabled
768+ if exempt_roles :
769+ payload ["exempt_roles" ] = exempt_roles
770+ if exempt_channels :
771+ payload ["exempt_channels" ] = exempt_channels
772+
773+ return await self ._req .request (
774+ Route ("PATCH" , f"/guilds/{ guild_id } /auto-moderation/rules/{ rule_id } " ),
775+ json = payload ,
776+ reason = reason ,
777+ )
778+
779+ async def delete_auto_moderation_rule (
780+ self , guild_id : int , rule_id : int , reason : Optional [str ] = None
781+ ) -> None :
782+ """
783+ Deletes an AutoMod rule.
784+ :param guild_id: Guild ID snowflake.
785+ :param rule_id: Rule ID snowflake.
786+ :param reason: Reason to send to audit log, if any.
787+ """
788+
789+ return await self ._req .request (
790+ Route ("DELETE" , f"/guilds/{ guild_id } /auto-moderation/rules/{ rule_id } " ), reason = reason
791+ )
0 commit comments