#Create Automod-Rule

1 messages · Page 1 of 1 (latest)

fair prism
#

I cant get any further i tried different ways of creating an automod rule with my bot but it seems that nothing happens. I didnt even get an error code. Just nothing. Maybe some of you can point me in the right direction.

@commands.slash_command(description="Erstellt eine Automoderation Regel")
@has_permissions(administrator=True)
  async def automodrule(self, ctx):
        bad_words = [
            "Hure", "Nutte", "Drecksack", "Spastiker", "Kleiner Fettsack", "Spast", "Pisser", "Wixxer", "Adminabuse", "Hurensohn", "Spatzenhirn"
        ]
        allowed_ones = [
            "kleiner", "Kleiner"
        ]
        hours = timedelta(hours=8)
        action_metadata = discord.AutoModActionMetadata(channel_id=1062101116797591653, timeout_duration=hours)
        action_def = discord.AutoModAction(discord.AutoModActionType.block_message, action_metadata)
        trigger_metadata = discord.AutoModTriggerMetadata(keyword_filter=bad_words, allow_list=allowed_ones)

        created_rule = await self.create_custom_auto_moderation_rule(
            name="AutoMod-Blacklist",
            event_type=discord.AutoModEventType.message_send,
            trigger_type=discord.AutoModTriggerType.keyword,
            trigger_metadata=trigger_metadata,
            actions=[action_def],
            exempt_channels=[1027891427205709885],
            reason="Zum Schutz vor Bad-Words!"
        )

        embed = discord.Embed(title='\n', description='\n', color=discord.Color.green())
        embed.set_author(name=f'Auto-Mod Regel wurde erstellt!', icon_url='https://cdn.discordapp.com/emojis/895062898844512307.png?size=96')
        await ctx.respond("", embed=embed, ephemeral=False)
        print("Created Rules:", created_rule)

This is my code so for

proven totem
#

doesnt print anything?

fair prism
#

And this is my Class so far and def for create_custom_auto_moderation_rule

class AutoMod(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    async def create_custom_auto_moderation_rule(self, name, event_type, trigger_type, trigger_metadata, actions, enabled=False, exempt_roles=None, exempt_channels=None, reason=None):
        rule = await self.bot.create_auto_moderation_rule(
            name=name,
            event_type=event_type,
            trigger_type=trigger_type,
            trigger_metadata=trigger_metadata,
            actions=actions,
            enabled=enabled,
            exempt_roles=exempt_roles,
            exempt_channels=exempt_channels,
            reason=reason,
        )
        return rule
fair prism
proven totem
#

wouldnt you need to create the rule on a guild

#

.rtfm Guild.create_auto_moderation_rule

fathom orchidBOT
fair prism
#

I tried my guild instead of self.bot. already

#

wont work either

proven totem
#

.rtfm Bot.create_auto_moderation_rule

fathom orchidBOT
#

Target not found, try again and make sure to check your spelling.

proven totem
#

well that method doesnt exist

#

you do it in a guild

fair prism
#

Ok well, even if i do it like this

 myguild = self.bot.get_guild(any int)
 created_rule = await myguild.create_custom_auto_moderation_rule(
            name="AutoMod-Blacklist",
            event_type=discord.AutoModEventType.message_send,
            trigger_type=discord.AutoModTriggerType.keyword,
            trigger_metadata=trigger_metadata,
            actions=[action_def],
            exempt_channels=[1027891427205709885],
            reason="Zum Schutz vor Bad-Words!"
        )
fair prism
proven totem
#

why dont you pass ctx.guild to the method

fair prism
#
await ctx.guild.create_custom_auto_moderation_rule

Still nothing

proven totem
#

@fair prism

#

.e py from datetime import timedelta hours = timedelta(hours=8) action_metadata = discord.AutoModActionMetadata(channel_id=1062101116797591653, timeout_duration=hours) action_def = discord.AutoModAction(discord.AutoModActionType.block_message, action_metadata) await ctx.guild.create_auto_moderation_rule( name="AutoMod-Blacklist", event_type=discord.AutoModEventType.message_send, trigger_type=discord.AutoModTriggerType.keyword, trigger_metadata=discord.AutoModTriggerMetadata(keyword_filter=["cock"]), actions=[action_def], reason="Zum Schutz vor Bad-Words!" )

#

this code works

#

exempt_channels take a list of discord.TextChannel

#

the library converts them to ID by itself

fair prism
# proven totem .e ```py from datetime import timedelta hours = timedelta(hours=8) action_metada...

This code works and generates the rule for you?

I changed it to this

@commands.slash_command(description="Erstellt eine Automoderation Regel")
@has_permissions(administrator=True)
    async def automodrule(self, ctx):
        hours = timedelta(hours=8)
        action_metadata = discord.AutoModActionMetadata(channel_id=1062101116797591653, timeout_duration=hours)
        action_def = discord.AutoModAction(discord.AutoModActionType.block_message, action_metadata)

        await ctx.guild.create_auto_moderation_rule(
            name="AutoMod-Blacklist",
            event_type=discord.AutoModEventType.message_send,
            trigger_type=discord.AutoModTriggerType.keyword,
            trigger_metadata=discord.AutoModTriggerMetadata(keyword_filter=["cock"]),
            actions=[action_def],
            exempt_channels=[1027891427205709885],
            reason="Zum Schutz vor Bad-Words!"
        )

        embed = discord.Embed(title='\n', description='\n', color=discord.Color.green())
        embed.set_author(name=f'Auto-Mod Regel wurde erstellt!', icon_url='https://cdn.discordapp.com/emojis/895062898844512307.png?size=96')
        await ctx.respond("", embed=embed, ephemeral=False)

And still cant see any action/issue at all.

proven totem
#

Like I said

fair prism
#

Im getting mad with this, still no progress

#

how does this even work for you lol. I get nothing at all

proven totem
#

Try copying my code

#

Exactly

#

And see if it works

fair prism
#

.rtfm automodactionmetadata

fathom orchidBOT
#

Target not found, try again and make sure to check your spelling.

fair prism
#
Application Command raised an exception: AttributeError: module 'discord' has no attribute 'AutoModActionMetadata'
#

So, these two have to be changed

action_metadata = discord.AutoModActionMetadata(channel_id=1062101116797591653, timeout_duration=hours)
action_def = discord.AutoModAction(discord.AutoModActionType.block_message, action_metadata)
proven totem
#

Cause it works for me

fair prism
proven totem
#

Update to 2.4.1

fair prism
#

It works with the latest version, ty!

#

I was a bit confused too, legit way of accessing classes...

#

.solved