Skip to content

Automod

Bases: Extension

Source code in extentions/automod.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
class AutoMod(Extension):
    def __init__(self, bot: Client):
        self.bot = bot
        self.phishing_links = list()
        plinks = requests.get('https://raw.githubusercontent.com/Discord-AntiScam/scam-links/main/urls.json')
        for link in json.loads(plinks.text):
            self.phishing_links.append(link)

    @listen()
    async def discord_automod_log(self, event: AutoModExec):
        if event.execution.action.type == 1:
            trigger_type = event.execution.rule_trigger_type
            content = event.execution.content
            guild = event.guild
            if trigger_type == 1:
                trigger = "BANNED WORD"
                reason = f"Message contains a banned word set by this community: {content}"
            elif trigger_type == 3:
                trigger = "SPAM"
                reason = f"Message contains spam: {content}"
            elif trigger_type == 4:
                trigger = "DISCORD BANNED WORD"
                reason = f"Message contains a banned word set by discord: {content}"
            elif trigger_type == 5:
                trigger = "MENTION SPAM"
                reason = f"Message exceeds the mention limit set by this community"
            audit_log_entry = await guild.fetch_audit_log(action_type=143, limit=1)
            for user in audit_log_entry.users:
                while True:
                    avid = random_string_generator()
                    strikes_db = await db.strikes.find_one({'guildid':guild.id, 'strikeid':avid})
                    if strikes_db is None:
                        break
                    else:
                        continue
                daytime = f'<t:{math.ceil(datetime.now().timestamp())}>'
                await db.strikes(strikeid=avid, guildid=guild.id, user=user.id, moderator=self.bot.user.id, action=f"Automod Message Block ({trigger})", day=daytime, reason=reason, automod=True).insert()

                settings = await db.amConfig.find_one({'guild':guild.id})
                channelid = await db.logs.find_one({"guild_id":guild.id})
                log_channel = guild.get_channel(channelid.channel_id)

                violation_entries = []
                async for entry in db.strikes.find({'guildid':guild.id, 'user':user.id, 'action':f"Automod Message Block ({trigger})", 'automod':True}):
                    violation_entries.append(entry.user)
                if settings.phishing.violation_count is not None:
                    if len(violation_entries) > settings.phishing.violation_count:

                        warnreason = f"{reason}. You've done this {len(violation_entries)} times, which exceeds our violations limit for {trigger} of {settings.phishing.violation_count}"

                        if 'warn' in settings.phishing.violation_punishment:
                            await automod_warn(event, log_channel, warnreason)

                        if 'mute' in settings.phishing.violation_punishment:
                            await automod_mute(event, settings, warnreason)

                        if 'kick' in settings.phishing.violation_punishment:
                            await guild.kick(user, warnreason)

                        if 'ban' in settings.phishing.violation_punishment:
                            await automod_ban(event, settings, warnreason)
    @listen()
    async def phishing_links_filter(self, event: MessageCreate):
        message = event.message
        user = message.author
        member = user
        guild = event.message.guild
        channel = message.channel
        if user.bot:
            return
        reason = f'[AUTOMOD]phishing link sent in {channel.name}'
        if await is_automod_event_active(guild, 'phishing_filter'):
            settings = await db.amConfig.find_one({'guild':guild.id})
            if settings.ignored_users is not None:
                if member.id in settings.ignored_users:
                    return
            if settings.ignored_roles is not None:
                if any(role for role in member.roles if role.id in settings.ignored_roles):
                    return
            if member.has_permission(Permissions.ADMINISTRATOR) == True:
                return
            if settings.ignored_channels is not None:
                if channel.id in settings.ignored_channels:
                    return
            urls = geturl(message.content)
            if urls is not None:
                for url in urls:
                    for link in self.phishing_links:
                        if link == url:
                            await message.delete()
                            await channel.send(f"Hey {user.mention}! That link is banned here!", delete_after=3)

                            await automod_strike(self, event, "Automod Log (Phishing Links)", reason)

                            channelid = await db.logs.find_one({"guild_id":guild.id})
                            log_channel = guild.get_channel(channelid.channel_id)

                            violation_entries = []
                            async for entry in db.strikes.find({'guildid':guild.id, 'user':user.id, 'action':"Automod Log (Phishing Links)", 'automod':True}):
                                violation_entries.append(entry.user)
                            if settings.phishing.violation_count is not None:
                                if len(violation_entries) > settings.phishing.violation_count:
                                    if 'warn' in settings.phishing.violation_punishment:
                                        await automod_warn(event, log_channel, reason)

                                    if 'mute' in settings.phishing.violation_punishment:
                                        await automod_mute(event, settings, reason)

                                    if 'kick' in settings.phishing.violation_punishment:
                                        await guild.kick(user, reason)

                                    if 'ban' in settings.phishing.violation_punishment:
                                        await automod_ban(event, settings, reason)

    psc = SlashCommand(name = 'phishing_links', description="Configure Melodys phishing links automod.", default_member_permissions=Permissions.ADMINISTRATOR)

    @psc.subcommand('violation_count', sub_cmd_description='How many violations before punishment.')
    @slash_option('violations_count', 'Must be between 0-10.', OptionType.INTEGER)
    async def phishing_links_violation_count(self, ctx: InteractionContext, violations_count:int=0):
        """
        /phishing_links violation_count
        Description:
            Configure how many violations are needed before Melody gives out a punishment.

        Args:
            violations_count: Must be between 0-10
        """
        # violations_count = get_num(violations_count)
        if (int(violations_count) > 10) or (int(violations_count) < 0):
            await ctx.send(f"{violations_count} is not a valid violation count. Violation count has to be between 0-10.")
        if violations_count is None:
            violations_count = 0
        settings = await db.automod_config.find_one({"guildid":ctx.guild_id})
        settings.phishing.violation_count = int(violations_count)
        await settings.save()
        await ctx.send(f'Violation count set to: {violations_count}')

    @psc.subcommand('punishments', sub_cmd_description='What punishments to use?')
    async def phishing_links_punishments(self, ctx: InteractionContext):
        """
        /phishing_links punishments
        Description:
            Configure what punishments will Melody give out.
        Usage:
            There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.
        """
        settings = await db.amConfig.find_one({'guildid':ctx.guild_id})
        if settings.phishing.violation_punishment is None:
            events_log_list = ''
        else:
            events_log_list = settings.phishing.violation_punishment

        if 'warn' in events_log_list:
            warn_status = True
        else:
            warn_status = False

        if 'mute' in events_log_list:
            mute_status = True
        else:
            mute_status = False

        if 'kick' in events_log_list:
            kick_status = True
        else:
            kick_status = False

        if 'ban' in events_log_list:
            ban_status = True
        else:
            ban_status = False

        select_options = [
            StringSelectOption(label="Warn", value="warn", default=warn_status),
            StringSelectOption(label="Mute", value="mute", default=mute_status),
            StringSelectOption(label="Kick", value="kick", default=kick_status),
            StringSelectOption(label="Ban", value="ban", default=ban_status)
        ]

        select_menu = StringSelectMenu(select_options, min_values=0, max_values=2)

        message = await ctx.send('Configure to what automod reacts to:', components=select_menu)

        while True:
            try:
                select = await self.bot.wait_for_component(components=select_menu, timeout=120)
            except asyncio.TimeoutError:
                await message.edit('Config closed due to 2 minutes of inactivity.', components=[])
            else:
                values = ','.join(select.ctx.values)
                settings.phishing.violation_punishment = values
                await settings.save()

    @listen()
    async def onNameChange_banned_name_exact(self, event: MemberUpdate):
        member =  event.after
        if await is_automod_event_active(event.guild, 'banned_names'):
            old_name =  event.before.display_name
            new_name = event.after.display_name
            if old_name != new_name:
                settings = await db.amConfig.find_one({'guild':event.guild.id})
                if settings.ignored_users is not None:
                    if member.id in settings.ignored_users:
                        return
                if settings.ignored_roles is not None:
                    if any(role for role in member.roles if role.id in settings.ignored_roles):
                        return
                if member.has_permission(Permissions.ADMINISTRATOR) == True:
                    return
                bn = await db.bannedNames.find_one({'guild':event.guild.id})
                if bn is None:
                    await db.bannedNames(guild=event.guild.id).insert()
                banned_names = bn.names
                new_name_result = process.extract(new_name, banned_names, scorer=fuzz.token_sort_ratio, limit=1)
                names = [t[0] for t in new_name_result if t[1] >= 90]
                username_result = process.extract(member.username, banned_names, scorer=fuzz.token_sort_ratio, limit=1)
                usernames = [t[0] for t in username_result if t[1] >= 90]
                if names != []:
                    name = ' '.join(names)
                    reason = f'Automod detected a banned name {name} in {new_name} for {member}({member.id})'
                    if usernames == []:
                        await member.edit_nickname(member.username, reason)
                    else:
                        await member.edit_nickname(bn.default_name, reason)
                    embed = Embed(description=reason,
                                            color=0xffcc50)
                    embed.set_thumbnail(url=member.avatar.url)
                    embed.add_field(name="Old Name", value=old_name)
                    embed.add_field(name="New Name", value=new_name)

                    channelid = await db.logs.find_one({"guild_id":member.guild.id})
                    log_channel = member.guild.get_channel(channelid.channel_id)
                    try:
                        await member.send(f"Your name or part of your name were flagged in banned names in `{event.guild.name}` server.\nI've flagged `{name}` in `{new_name}`")
                        await log_channel.send(f'I DMed {member}', embed=embed)
                    except Exception:
                        await log_channel.send(f"Couldn't DM {member}", embed=embed)

                    violation_count = await db.strikes.find({'guildid':event.guild.id, 'user':member.id, 'action':"Automod Log (Banned Name)", 'automod':True}).count()
                    if settings.banned_names.violation_count is not None:
                        if violation_count > settings.banned_names.violation_count:
                            if 'warn' in settings.banned_names.violation_punishment:
                                await automod_warn(event, log_channel, reason)

                            if 'mute' in settings.banned_names.violation_punishment:
                                await automod_mute(event, settings, reason)

                            if 'kick' in settings.banned_names.violation_punishment:
                                await event.guild.kick(member, reason)

                            if 'ban' in settings.banned_names.violation_punishment:
                                await automod_ban(event, settings, reason)

    @listen()
    async def onMemAdd_banned_name_exact(self, event: MemberAdd):
        member =  event.member
        if await is_automod_event_active(event.guild, 'banned_names'):
            new_name = member.display_name
            settings = await db.amConfig.find_one({'guild':event.guild.id})
            if settings.ignored_users is not None:
                if member.id in settings.ignored_users:
                    return
            if settings.ignored_roles is not None:
                if any(role for role in member.roles if role.id in settings.ignored_roles):
                    return
            if member.has_permission(Permissions.ADMINISTRATOR) == True:
                return
            bn = await db.bannedNames.find_one({'guild':event.guild.id})
            if bn is None:
                await db.bannedNames(guild=event.guild.id).insert()
            banned_names = bn.names
            new_name_result = process.extract(new_name, banned_names, scorer=fuzz.token_sort_ratio, limit=1)
            names = [t[0] for t in new_name_result if t[1] >= 90]
            if names != []:
                name = ' '.join(names)
                reason = f'Automod detected a banned name {name} in {new_name} for {member}({member.id})'
                await member.edit_nickname(bn.default_name, reason)
                embed = Embed(description=reason,
                                        color=0xffcc50)
                embed.set_thumbnail(url=member.avatar.url)

                channelid = await db.logs.find_one({"guild_id":member.guild.id})
                log_channel = member.guild.get_channel(channelid.channel_id)
                try:
                    await member.send(f"Your name or part of your name were flagged in banned names in `{event.guild.name}` server.\nI've flagged `{name}` in `{new_name}`")
                    await log_channel.send(f'I DMed {member}', embed=embed)
                except Exception:
                    await log_channel.send(f"Couldn't DM {member}", embed=embed)

                violation_count = await db.strikes.find({'guildid':event.guild.id, 'user':member.id, 'action':"Automod Log (Banned Name)", 'automod':True}).count()
                if settings.banned_names.violation_count is not None:
                    if violation_count > settings.banned_names.violation_count:
                        if 'warn' in settings.banned_names.violation_punishment:
                            await automod_warn(event, log_channel, reason)

                        if 'mute' in settings.banned_names.violation_punishment:
                            await automod_mute(event, settings, reason)

                        if 'kick' in settings.banned_names.violation_punishment:
                            await event.guild.kick(member, reason)

                        if 'ban' in settings.banned_names.violation_punishment:
                            await automod_ban(event, settings, reason)

    BannedNames = SlashCommand(name='banned_names', default_member_permissions=Permissions.ADMINISTRATOR, description='Manage banned names.')

    @BannedNames.subcommand(sub_cmd_name='manage', sub_cmd_description='Manage banned names')
    async def banned_names_manage(self, ctx:InteractionContext):
        """
        /banned_names manage
        Description:
            Manage banned names.
        Usage:
            Use the command to get a muodal menu for configuration. Config will be saved on modal submit. Config time limit is 10 minutes.
        """
        bn = await db.bannedNames.find_one({'guild':ctx.guild.id})
        settings = await db.amConfig.find_one({"guild":ctx.guild_id})
        if settings.banned_names.violation_count is None:
            bw_vc_pf = MISSING
        else:
            bw_vc_pf = settings.banned_names.violation_count

        if bn is None:
            exact_prefill = MISSING
            defname_prefill = MISSING
        else:
            if bn.names is None:
                exact_prefill = MISSING
            else:
                exact_prefill = ','.join(bn.names)
            if bn.default_name is None:
                defname_prefill = MISSING
            else:
                defname_prefill = bn.default_name
        m = Modal(title='Configure the automatic moderation', components=[
            InputText(
                label="Banned Names",
                style=TextStyles.PARAGRAPH,
                custom_id=f'exact_match',
                placeholder='Words, seperated by a comma(,). They should have minimum 3 characters.',
                value=exact_prefill,
                required=False
            ),
            InputText(
                label="Fallback Name",
                style=TextStyles.SHORT,
                custom_id=f'defname',
                placeholder="One name that will be act as a fallback",
                value=defname_prefill,
                required=True,
                max_length=32,
                min_length=2
            ),
            InputText(
                label="Violation Count",
                style=TextStyles.SHORT,
                custom_id=f'bw_vc',
                placeholder="Must be between 0-10.",
                value=bw_vc_pf,
                required=False
            )
        ],custom_id=f'{ctx.author.id}_automod_config_modal')

        await ctx.send_modal(modal=m)
        try:
            modal_recived: ModalContext = await self.bot.wait_for_modal(modal=m, author=ctx.author.id, timeout=600)
        except asyncio.TimeoutError:
            return await modal_recived.send(f":x: Uh oh, {ctx.author.mention}! You took longer than 10 minutes to respond to this ", ephemeral=True)

        em_words = modal_recived.responses.get('exact_match')
        defName = modal_recived.responses.get('defname')

        bw_vc_response = modal_recived.responses.get('bw_vc')
        if (bw_vc_response == '') or (bw_vc_response is None):
            bw_vc_response = None
        elif (get_num(bw_vc_response) > 10) or (get_num(bw_vc_response) < 0):
            await modal_recived.send(f"{bw_vc_response} is not a valid violation count. Violation count has to be between 0-10.")

        settings.banned_names.violation_count = get_num(bw_vc_response)
        await settings.save()

        if bn is None:
            await db.bannedNames(guild=ctx.guild_id, names=em_words.split(','), default_name=defName).insert()
        else:
            bn.default_name = defName
            bn.names = em_words.split(',')
            await bn.save()

        embed=Embed(color=0xffcc50,
        description=f'**Current banned names:**\n{em_words}\n**Violation count:** {bw_vc_response}')
        await modal_recived.send(embed=embed)

    @BannedNames.subcommand('punishments', sub_cmd_description='What punishments to use?')
    async def banned_names_punishments(self, ctx: InteractionContext):
        """
        /banned_names punishments
        Description:
            Configure what punishments will Melody give out.
        Usage:
            There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.
        """
        settings = await db.amConfig.find_one({'guildid':ctx.guild_id})
        if settings.banned_names.violation_punishment is None:
            events_log_list = ''
        else:
            events_log_list = settings.banned_names.violation_punishment

        if 'warn' in events_log_list:
            warn_status = True
        else:
            warn_status = False

        if 'mute' in events_log_list:
            mute_status = True
        else:
            mute_status = False

        if 'kick' in events_log_list:
            kick_status = True
        else:
            kick_status = False

        if 'ban' in events_log_list:
            ban_status = True
        else:
            ban_status = False

        select_options = [
            StringSelectOption(label="Warn", value="warn", default=warn_status),
            StringSelectOption(label="Mute", value="mute", default=mute_status),
            StringSelectOption(label="Kick", value="kick", default=kick_status),
            StringSelectOption(label="Ban", value="ban", default=ban_status)
        ]

        select_menu = StringSelectMenu(select_options, min_values=0, max_values=2)

        message = await ctx.send('Configure to what automod reacts to:', components=select_menu)

        while True:
            try:
                select = await self.bot.wait_for_component(components=select_menu, timeout=120)
            except asyncio.TimeoutError:
                await message.edit('Config closed due to 2 minutes of inactivity.', components=[])
            else:
                values = ','.join(select.ctx.values)
                settings.banned_names.violation_punishment = values
                await settings.save()

    AutoModSettings = SlashCommand(name='automod', default_member_permissions=Permissions.ADMINISTRATOR, description='Manage the automod.')

    @AutoModSettings.subcommand(sub_cmd_name='listen_to_events', sub_cmd_description='Activate parts of the automod')
    async def automod_events(self, ctx: InteractionContext):
        """
        /automod listen_to_events
        Description:
            Configure what AutoMod events will Melody listen to in the server.
        Usage:
            There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.
        """
        await ctx.defer(ephemeral=True)
        events = await db.amConfig.find_one({'guildid':ctx.guild_id})
        if events.active_events is None:
            events_log_list = []
        else:
            events_log_list = events.active_events
        if 'banned_names' in events_log_list:
            bn_status = True
        else:
            bn_status = False

        if 'phishing_filter' in events_log_list:
            pf_status = True
        else:
            pf_status = False

        select_options = [
            StringSelectOption(label="Banned Names", value="banned_names", default=bn_status),
            StringSelectOption(label="phishing_filter", value="phishing_filter", default=pf_status),
        ]

        select_menu = StringSelectMenu(select_options, min_values=0, max_values=2)

        message = await ctx.send('Configure to what automod reacts to:', components=select_menu)

        while True:
            try:
                select = await self.bot.wait_for_component(components=select_menu, timeout=120)
            except asyncio.TimeoutError:
                await message.edit('Config closed due to 2 minutes of inactivity.', components=[])
            else:
                events.active_events = select.ctx.values
                await events.save()

    @AutoModSettings.subcommand(sub_cmd_name='ban_mute_times', sub_cmd_description='Define a ban and mute times.')
    @slash_option(name="bantime", description="tempban time, examples: 10 S, 10 M, 10 H, 10 D", opt_type=OptionType.INTEGER, required=False)
    @slash_option(name="mutetime", description="mute time, examples: 10 S, 10 M, 10 H, 10 D", opt_type=OptionType.INTEGER, required=False)
    async def automod_ban_mute_times(self, ctx:InteractionContext, bantime:int=0, mutetime:int=0):
        """
        /automod ban_mute_times
        Description:
            Configure the temp ban and mute times Melody will use in automod.

        Args:
            bantime (int, optional): tempban time, examples: 10 S, 10 M, 10 H, 10 D" Defaults to 0.
            mutetime (int, optional): mute time, examples: 10 S, 10 M, 10 H, 10 D Defaults to 0.
        """
        if bantime is not None:
            bt = await bm_time_to_sec(ctx, bantime)
        else:
            bt = bantime
        if mutetime is not None:
            mt = await bm_time_to_sec(ctx, mutetime)
        else:
            mt = mutetime
        settings = await db.automod_config.find_one({"guildid":ctx.guild_id})
        settings.ban_time = bt
        settings.mute_time = mt
        await settings.save()
        await ctx.send(f'Ban time: {bantime}\nMute time: {mutetime}')

    @AutoModSettings.subcommand('ignored_channel', 'add', 'Add a channel to ignored channels.')
    @channel()
    async def AutomodAddIgnoredChannels(self, ctx:InteractionContext, channel: OptionType.CHANNEL=None):
        """
        /automod ignored_channel add
        Description:
            Add a channel to channels ignored by AutoMod.

        Args:
            channel (OptionType.CHANNEL, optional): The channel you want to add. Defaults to channel you're executing the command from.
        """
        await ctx.defer(ephemeral=True)
        if channel is None:
            channel = ctx.channel
        settings = await db.amConfig.find_one({"guild":ctx.guild.id})
        if settings is None:
            await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
        ignored_channels = settings.ignored_channels
        if ignored_channels is None:
            ignored_channels = list()
        if channel.id in ignored_channels:
            await ctx.send(f'{channel.mention} is already ignored.', ephemeral=True)
        ignored_channels.append(channel.id)
        await settings.save()
        channel_mentions = [ctx.guild.get_channel(id) for id in ignored_channels]
        channel_mentions = [ch.mention for ch in channel_mentions if ch is not None]
        channel_mentions = ' '.join(channel_mentions)
        embed = Embed(description=f"Channel {channel.mention} set to be ignored.")
        embed.add_field('Ignored Channels', channel_mentions)
        await ctx.send(embed=embed, ephemeral=True)

    @AutoModSettings.subcommand('ignored_channel', 'remove', 'Remove a channel from ignored channels.')
    @channel()
    async def AutomodRemoveIgnoredChannels(self, ctx:InteractionContext, channel: OptionType.CHANNEL=None):
        """
        /automod ignored_channel remove
        Description:
            Remove a channel from channels ignored by AutoMod.

        Args:
            channel (OptionType.CHANNEL, optional): The channel you want to remove. Defaults to channel you're executing the command from.
        """
        await ctx.defer(ephemeral=True)
        if channel is None:
            channel = ctx.channel
        settings = await db.amConfig.find_one({"guild":ctx.guild.id})
        if settings is None:
            await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
        ignored_channels = settings.ignored_channels
        if ignored_channels is None:
            ignored_channels = list()
        if channel.id not in ignored_channels:
            await ctx.send(f'{channel.mention} is not being ignored by automod.', ephemeral=True)
        ignored_channels.remove(channel.id)
        await settings.save()
        channel_mentions = [ctx.guild.get_channel(id) for id in ignored_channels]
        channel_mentions = [ch.mention for ch in channel_mentions if ch is not None]
        channel_mentions = ' '.join(channel_mentions)
        embed = Embed(description=f"Channel {channel.mention} removed from ignored channels.")
        embed.add_field('Ignored Channels', channel_mentions)
        await ctx.send(embed=embed, ephemeral=True)

    @AutoModSettings.subcommand('ignored_role', 'add', 'Make a role to be ignored by automod.')
    @role()
    async def AutomodAddIgnoredRoles(self, ctx:InteractionContext, role: OptionType.ROLE):
        """
        /automod ignored_role add
        Description:
            Add a role to roles ignored by AutoMod.

        Args:
            role (OptionType.ROLE): The role you want to add.
        """
        await ctx.defer(ephemeral=True)
        settings = await db.amConfig.find_one({"guild":ctx.guild.id})
        if settings is None:
            await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
        ignored_roles = settings.ignored_roles
        if ignored_roles is None:
            ignored_roles = list()
        if role.id in ignored_roles:
            await ctx.send(f'{role.mention} is already ignored.', ephemeral=True)
        ignored_roles.append(role.id)
        await settings.save()
        role_mentions = [ctx.guild.get_role(id) for id in ignored_roles]
        role_mentions = [r.mention for r in role_mentions if r is not None]
        role_mentions = ' '.join(role_mentions)
        embed = Embed(description=f"Role {role.mention} was added to roles ignored by automod.")
        embed.add_field('Ignored Roles', role_mentions)
        await ctx.send(embed=embed, ephemeral=True)

    @AutoModSettings.subcommand('ignored_role', 'remove', 'Remove a role from ignored roles.')
    @role()
    async def AutomodRemoveIgnoredRoles(self, ctx:InteractionContext, role: OptionType.ROLE):
        """
        /automod ignored_role remove
        Description:
            Remove a role from roles ignored by AutoMod.

        Args:
            role (OptionType.ROLE): The role you want to remove.
        """
        await ctx.defer(ephemeral=True)
        settings = await db.amConfig.find_one({"guild":ctx.guild.id})
        if settings is None:
            await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
        ignored_roles = settings.ignored_roles
        if ignored_roles is None:
            ignored_roles = list()
        if role.id not in ignored_roles:
            await ctx.send(f'{role.mention} is not being ignored by automod.', ephemeral=True)
        ignored_roles.remove(role.id)
        await settings.save()
        role_mentions = [ctx.guild.get_role(id) for id in ignored_roles]
        role_mentions = [r.mention for r in role_mentions if r is not None]
        role_mentions = ' '.join(role_mentions)
        embed = Embed(description=f"Role {role.mention} was removed from roles ignored by automod.")
        embed.add_field('Ignored Roles', role_mentions)
        await ctx.send(embed=embed, ephemeral=True)

    @AutoModSettings.subcommand('ignored_member', 'add', 'Make a member to be ignored by automod.')
    @user()
    async def AutomodAddIgnoredMember(self, ctx:InteractionContext, user: OptionType.USER):
        """
        /automod ignored_member add
        Description:
            Add a member to members ignored by AutoMod.

        Args:
            user (OptionType.USER): member to be ignored by automod
        """
        await ctx.defer(ephemeral=True)
        settings = await db.amConfig.find_one({"guild":ctx.guild.id})
        if settings is None:
            await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
        ignored_users = settings.ignored_users
        if ignored_users is None:
            ignored_users = list()
        if user.id in ignored_users:
            await ctx.send(f'{user}|{user.id} is already ignored.', ephemeral=True)
        ignored_users.append(user.id)
        await settings.save()
        users = [ctx.guild.get_member(id) for id in ignored_users]
        users = [f'{r}({r.id})' for r in users if r is not None]
        users = ' '.join(users)
        embed = Embed(description=f"Member {user}({user.id}) was added to members ignored by automod.")
        embed.add_field('Ignored Members', users)
        await ctx.send(embed=embed, ephemeral=True)

    @AutoModSettings.subcommand('ignored_member', 'remove', 'Remove a member from ignored members.')
    @user()
    async def AutomodRemoveIgnoredMember(self, ctx:InteractionContext, user: OptionType.USER):
        """
        /automod ignored_member remove
        Description:
            Remove a member from members ignored by AutoMod.

        Args:
            user (OptionType.USER): member to be removed from ignored members by automod
        """
        await ctx.defer(ephemeral=True)
        settings = await db.amConfig.find_one({"guild":ctx.guild.id})
        if settings is None:
           await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
        ignored_users = settings.ignored_users
        if ignored_users is None:
            ignored_users = list()
        if user.id not in ignored_users:
            await ctx.send(f'{user}|{user.id} is not being ignored by automod.', ephemeral=True)
        ignored_users.remove(user.id)
        await settings.save()
        users = [ctx.guild.get_member(id) for id in ignored_users]
        users = [f'{r}({r.id})' for r in users if r is not None]
        users = ' '.join(users)
        embed = Embed(description=f"Member {user}({user.id}) was removed from members ignored by automod.")
        embed.add_field('Ignored Members', users)
        await ctx.send(embed=embed, ephemeral=True)

/phishing_links violation_count

Description

Configure how many violations are needed before Melody gives out a punishment.

Parameters:

Name Type Description Default
violations_count int

Must be between 0-10

0
Source code in extentions/automod.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
@psc.subcommand('violation_count', sub_cmd_description='How many violations before punishment.')
@slash_option('violations_count', 'Must be between 0-10.', OptionType.INTEGER)
async def phishing_links_violation_count(self, ctx: InteractionContext, violations_count:int=0):
    """
    /phishing_links violation_count
    Description:
        Configure how many violations are needed before Melody gives out a punishment.

    Args:
        violations_count: Must be between 0-10
    """
    # violations_count = get_num(violations_count)
    if (int(violations_count) > 10) or (int(violations_count) < 0):
        await ctx.send(f"{violations_count} is not a valid violation count. Violation count has to be between 0-10.")
    if violations_count is None:
        violations_count = 0
    settings = await db.automod_config.find_one({"guildid":ctx.guild_id})
    settings.phishing.violation_count = int(violations_count)
    await settings.save()
    await ctx.send(f'Violation count set to: {violations_count}')

/phishing_links punishments

Description

Configure what punishments will Melody give out.

Usage

There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.

Source code in extentions/automod.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
@psc.subcommand('punishments', sub_cmd_description='What punishments to use?')
async def phishing_links_punishments(self, ctx: InteractionContext):
    """
    /phishing_links punishments
    Description:
        Configure what punishments will Melody give out.
    Usage:
        There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.
    """
    settings = await db.amConfig.find_one({'guildid':ctx.guild_id})
    if settings.phishing.violation_punishment is None:
        events_log_list = ''
    else:
        events_log_list = settings.phishing.violation_punishment

    if 'warn' in events_log_list:
        warn_status = True
    else:
        warn_status = False

    if 'mute' in events_log_list:
        mute_status = True
    else:
        mute_status = False

    if 'kick' in events_log_list:
        kick_status = True
    else:
        kick_status = False

    if 'ban' in events_log_list:
        ban_status = True
    else:
        ban_status = False

    select_options = [
        StringSelectOption(label="Warn", value="warn", default=warn_status),
        StringSelectOption(label="Mute", value="mute", default=mute_status),
        StringSelectOption(label="Kick", value="kick", default=kick_status),
        StringSelectOption(label="Ban", value="ban", default=ban_status)
    ]

    select_menu = StringSelectMenu(select_options, min_values=0, max_values=2)

    message = await ctx.send('Configure to what automod reacts to:', components=select_menu)

    while True:
        try:
            select = await self.bot.wait_for_component(components=select_menu, timeout=120)
        except asyncio.TimeoutError:
            await message.edit('Config closed due to 2 minutes of inactivity.', components=[])
        else:
            values = ','.join(select.ctx.values)
            settings.phishing.violation_punishment = values
            await settings.save()

banned_names_manage(ctx) async

/banned_names manage

Description

Manage banned names.

Usage

Use the command to get a muodal menu for configuration. Config will be saved on modal submit. Config time limit is 10 minutes.

Source code in extentions/automod.py
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
@BannedNames.subcommand(sub_cmd_name='manage', sub_cmd_description='Manage banned names')
async def banned_names_manage(self, ctx:InteractionContext):
    """
    /banned_names manage
    Description:
        Manage banned names.
    Usage:
        Use the command to get a muodal menu for configuration. Config will be saved on modal submit. Config time limit is 10 minutes.
    """
    bn = await db.bannedNames.find_one({'guild':ctx.guild.id})
    settings = await db.amConfig.find_one({"guild":ctx.guild_id})
    if settings.banned_names.violation_count is None:
        bw_vc_pf = MISSING
    else:
        bw_vc_pf = settings.banned_names.violation_count

    if bn is None:
        exact_prefill = MISSING
        defname_prefill = MISSING
    else:
        if bn.names is None:
            exact_prefill = MISSING
        else:
            exact_prefill = ','.join(bn.names)
        if bn.default_name is None:
            defname_prefill = MISSING
        else:
            defname_prefill = bn.default_name
    m = Modal(title='Configure the automatic moderation', components=[
        InputText(
            label="Banned Names",
            style=TextStyles.PARAGRAPH,
            custom_id=f'exact_match',
            placeholder='Words, seperated by a comma(,). They should have minimum 3 characters.',
            value=exact_prefill,
            required=False
        ),
        InputText(
            label="Fallback Name",
            style=TextStyles.SHORT,
            custom_id=f'defname',
            placeholder="One name that will be act as a fallback",
            value=defname_prefill,
            required=True,
            max_length=32,
            min_length=2
        ),
        InputText(
            label="Violation Count",
            style=TextStyles.SHORT,
            custom_id=f'bw_vc',
            placeholder="Must be between 0-10.",
            value=bw_vc_pf,
            required=False
        )
    ],custom_id=f'{ctx.author.id}_automod_config_modal')

    await ctx.send_modal(modal=m)
    try:
        modal_recived: ModalContext = await self.bot.wait_for_modal(modal=m, author=ctx.author.id, timeout=600)
    except asyncio.TimeoutError:
        return await modal_recived.send(f":x: Uh oh, {ctx.author.mention}! You took longer than 10 minutes to respond to this ", ephemeral=True)

    em_words = modal_recived.responses.get('exact_match')
    defName = modal_recived.responses.get('defname')

    bw_vc_response = modal_recived.responses.get('bw_vc')
    if (bw_vc_response == '') or (bw_vc_response is None):
        bw_vc_response = None
    elif (get_num(bw_vc_response) > 10) or (get_num(bw_vc_response) < 0):
        await modal_recived.send(f"{bw_vc_response} is not a valid violation count. Violation count has to be between 0-10.")

    settings.banned_names.violation_count = get_num(bw_vc_response)
    await settings.save()

    if bn is None:
        await db.bannedNames(guild=ctx.guild_id, names=em_words.split(','), default_name=defName).insert()
    else:
        bn.default_name = defName
        bn.names = em_words.split(',')
        await bn.save()

    embed=Embed(color=0xffcc50,
    description=f'**Current banned names:**\n{em_words}\n**Violation count:** {bw_vc_response}')
    await modal_recived.send(embed=embed)

banned_names_punishments(ctx) async

/banned_names punishments

Description

Configure what punishments will Melody give out.

Usage

There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.

Source code in extentions/automod.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
@BannedNames.subcommand('punishments', sub_cmd_description='What punishments to use?')
async def banned_names_punishments(self, ctx: InteractionContext):
    """
    /banned_names punishments
    Description:
        Configure what punishments will Melody give out.
    Usage:
        There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.
    """
    settings = await db.amConfig.find_one({'guildid':ctx.guild_id})
    if settings.banned_names.violation_punishment is None:
        events_log_list = ''
    else:
        events_log_list = settings.banned_names.violation_punishment

    if 'warn' in events_log_list:
        warn_status = True
    else:
        warn_status = False

    if 'mute' in events_log_list:
        mute_status = True
    else:
        mute_status = False

    if 'kick' in events_log_list:
        kick_status = True
    else:
        kick_status = False

    if 'ban' in events_log_list:
        ban_status = True
    else:
        ban_status = False

    select_options = [
        StringSelectOption(label="Warn", value="warn", default=warn_status),
        StringSelectOption(label="Mute", value="mute", default=mute_status),
        StringSelectOption(label="Kick", value="kick", default=kick_status),
        StringSelectOption(label="Ban", value="ban", default=ban_status)
    ]

    select_menu = StringSelectMenu(select_options, min_values=0, max_values=2)

    message = await ctx.send('Configure to what automod reacts to:', components=select_menu)

    while True:
        try:
            select = await self.bot.wait_for_component(components=select_menu, timeout=120)
        except asyncio.TimeoutError:
            await message.edit('Config closed due to 2 minutes of inactivity.', components=[])
        else:
            values = ','.join(select.ctx.values)
            settings.banned_names.violation_punishment = values
            await settings.save()

automod_events(ctx) async

/automod listen_to_events

Description

Configure what AutoMod events will Melody listen to in the server.

Usage

There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.

Source code in extentions/automod.py
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
@AutoModSettings.subcommand(sub_cmd_name='listen_to_events', sub_cmd_description='Activate parts of the automod')
async def automod_events(self, ctx: InteractionContext):
    """
    /automod listen_to_events
    Description:
        Configure what AutoMod events will Melody listen to in the server.
    Usage:
        There are no parameters in this command, you just have to use it, and it will send you a configuration selection menu. Selections are automatically saved. Config time limit is 2 minutes.
    """
    await ctx.defer(ephemeral=True)
    events = await db.amConfig.find_one({'guildid':ctx.guild_id})
    if events.active_events is None:
        events_log_list = []
    else:
        events_log_list = events.active_events
    if 'banned_names' in events_log_list:
        bn_status = True
    else:
        bn_status = False

    if 'phishing_filter' in events_log_list:
        pf_status = True
    else:
        pf_status = False

    select_options = [
        StringSelectOption(label="Banned Names", value="banned_names", default=bn_status),
        StringSelectOption(label="phishing_filter", value="phishing_filter", default=pf_status),
    ]

    select_menu = StringSelectMenu(select_options, min_values=0, max_values=2)

    message = await ctx.send('Configure to what automod reacts to:', components=select_menu)

    while True:
        try:
            select = await self.bot.wait_for_component(components=select_menu, timeout=120)
        except asyncio.TimeoutError:
            await message.edit('Config closed due to 2 minutes of inactivity.', components=[])
        else:
            events.active_events = select.ctx.values
            await events.save()

automod_ban_mute_times(ctx, bantime=0, mutetime=0) async

/automod ban_mute_times

Description

Configure the temp ban and mute times Melody will use in automod.

Parameters:

Name Type Description Default
bantime int

tempban time, examples: 10 S, 10 M, 10 H, 10 D" Defaults to 0.

0
mutetime int

mute time, examples: 10 S, 10 M, 10 H, 10 D Defaults to 0.

0
Source code in extentions/automod.py
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
@AutoModSettings.subcommand(sub_cmd_name='ban_mute_times', sub_cmd_description='Define a ban and mute times.')
@slash_option(name="bantime", description="tempban time, examples: 10 S, 10 M, 10 H, 10 D", opt_type=OptionType.INTEGER, required=False)
@slash_option(name="mutetime", description="mute time, examples: 10 S, 10 M, 10 H, 10 D", opt_type=OptionType.INTEGER, required=False)
async def automod_ban_mute_times(self, ctx:InteractionContext, bantime:int=0, mutetime:int=0):
    """
    /automod ban_mute_times
    Description:
        Configure the temp ban and mute times Melody will use in automod.

    Args:
        bantime (int, optional): tempban time, examples: 10 S, 10 M, 10 H, 10 D" Defaults to 0.
        mutetime (int, optional): mute time, examples: 10 S, 10 M, 10 H, 10 D Defaults to 0.
    """
    if bantime is not None:
        bt = await bm_time_to_sec(ctx, bantime)
    else:
        bt = bantime
    if mutetime is not None:
        mt = await bm_time_to_sec(ctx, mutetime)
    else:
        mt = mutetime
    settings = await db.automod_config.find_one({"guildid":ctx.guild_id})
    settings.ban_time = bt
    settings.mute_time = mt
    await settings.save()
    await ctx.send(f'Ban time: {bantime}\nMute time: {mutetime}')

AutomodAddIgnoredChannels(ctx, channel=None) async

/automod ignored_channel add

Description

Add a channel to channels ignored by AutoMod.

Parameters:

Name Type Description Default
channel OptionType.CHANNEL

The channel you want to add. Defaults to channel you're executing the command from.

None
Source code in extentions/automod.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
@AutoModSettings.subcommand('ignored_channel', 'add', 'Add a channel to ignored channels.')
@channel()
async def AutomodAddIgnoredChannels(self, ctx:InteractionContext, channel: OptionType.CHANNEL=None):
    """
    /automod ignored_channel add
    Description:
        Add a channel to channels ignored by AutoMod.

    Args:
        channel (OptionType.CHANNEL, optional): The channel you want to add. Defaults to channel you're executing the command from.
    """
    await ctx.defer(ephemeral=True)
    if channel is None:
        channel = ctx.channel
    settings = await db.amConfig.find_one({"guild":ctx.guild.id})
    if settings is None:
        await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
    ignored_channels = settings.ignored_channels
    if ignored_channels is None:
        ignored_channels = list()
    if channel.id in ignored_channels:
        await ctx.send(f'{channel.mention} is already ignored.', ephemeral=True)
    ignored_channels.append(channel.id)
    await settings.save()
    channel_mentions = [ctx.guild.get_channel(id) for id in ignored_channels]
    channel_mentions = [ch.mention for ch in channel_mentions if ch is not None]
    channel_mentions = ' '.join(channel_mentions)
    embed = Embed(description=f"Channel {channel.mention} set to be ignored.")
    embed.add_field('Ignored Channels', channel_mentions)
    await ctx.send(embed=embed, ephemeral=True)

AutomodRemoveIgnoredChannels(ctx, channel=None) async

/automod ignored_channel remove

Description

Remove a channel from channels ignored by AutoMod.

Parameters:

Name Type Description Default
channel OptionType.CHANNEL

The channel you want to remove. Defaults to channel you're executing the command from.

None
Source code in extentions/automod.py
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
@AutoModSettings.subcommand('ignored_channel', 'remove', 'Remove a channel from ignored channels.')
@channel()
async def AutomodRemoveIgnoredChannels(self, ctx:InteractionContext, channel: OptionType.CHANNEL=None):
    """
    /automod ignored_channel remove
    Description:
        Remove a channel from channels ignored by AutoMod.

    Args:
        channel (OptionType.CHANNEL, optional): The channel you want to remove. Defaults to channel you're executing the command from.
    """
    await ctx.defer(ephemeral=True)
    if channel is None:
        channel = ctx.channel
    settings = await db.amConfig.find_one({"guild":ctx.guild.id})
    if settings is None:
        await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
    ignored_channels = settings.ignored_channels
    if ignored_channels is None:
        ignored_channels = list()
    if channel.id not in ignored_channels:
        await ctx.send(f'{channel.mention} is not being ignored by automod.', ephemeral=True)
    ignored_channels.remove(channel.id)
    await settings.save()
    channel_mentions = [ctx.guild.get_channel(id) for id in ignored_channels]
    channel_mentions = [ch.mention for ch in channel_mentions if ch is not None]
    channel_mentions = ' '.join(channel_mentions)
    embed = Embed(description=f"Channel {channel.mention} removed from ignored channels.")
    embed.add_field('Ignored Channels', channel_mentions)
    await ctx.send(embed=embed, ephemeral=True)

AutomodAddIgnoredRoles(ctx, role) async

/automod ignored_role add

Description

Add a role to roles ignored by AutoMod.

Parameters:

Name Type Description Default
role OptionType.ROLE

The role you want to add.

required
Source code in extentions/automod.py
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
@AutoModSettings.subcommand('ignored_role', 'add', 'Make a role to be ignored by automod.')
@role()
async def AutomodAddIgnoredRoles(self, ctx:InteractionContext, role: OptionType.ROLE):
    """
    /automod ignored_role add
    Description:
        Add a role to roles ignored by AutoMod.

    Args:
        role (OptionType.ROLE): The role you want to add.
    """
    await ctx.defer(ephemeral=True)
    settings = await db.amConfig.find_one({"guild":ctx.guild.id})
    if settings is None:
        await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
    ignored_roles = settings.ignored_roles
    if ignored_roles is None:
        ignored_roles = list()
    if role.id in ignored_roles:
        await ctx.send(f'{role.mention} is already ignored.', ephemeral=True)
    ignored_roles.append(role.id)
    await settings.save()
    role_mentions = [ctx.guild.get_role(id) for id in ignored_roles]
    role_mentions = [r.mention for r in role_mentions if r is not None]
    role_mentions = ' '.join(role_mentions)
    embed = Embed(description=f"Role {role.mention} was added to roles ignored by automod.")
    embed.add_field('Ignored Roles', role_mentions)
    await ctx.send(embed=embed, ephemeral=True)

AutomodRemoveIgnoredRoles(ctx, role) async

/automod ignored_role remove

Description

Remove a role from roles ignored by AutoMod.

Parameters:

Name Type Description Default
role OptionType.ROLE

The role you want to remove.

required
Source code in extentions/automod.py
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
@AutoModSettings.subcommand('ignored_role', 'remove', 'Remove a role from ignored roles.')
@role()
async def AutomodRemoveIgnoredRoles(self, ctx:InteractionContext, role: OptionType.ROLE):
    """
    /automod ignored_role remove
    Description:
        Remove a role from roles ignored by AutoMod.

    Args:
        role (OptionType.ROLE): The role you want to remove.
    """
    await ctx.defer(ephemeral=True)
    settings = await db.amConfig.find_one({"guild":ctx.guild.id})
    if settings is None:
        await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
    ignored_roles = settings.ignored_roles
    if ignored_roles is None:
        ignored_roles = list()
    if role.id not in ignored_roles:
        await ctx.send(f'{role.mention} is not being ignored by automod.', ephemeral=True)
    ignored_roles.remove(role.id)
    await settings.save()
    role_mentions = [ctx.guild.get_role(id) for id in ignored_roles]
    role_mentions = [r.mention for r in role_mentions if r is not None]
    role_mentions = ' '.join(role_mentions)
    embed = Embed(description=f"Role {role.mention} was removed from roles ignored by automod.")
    embed.add_field('Ignored Roles', role_mentions)
    await ctx.send(embed=embed, ephemeral=True)

AutomodAddIgnoredMember(ctx, user) async

/automod ignored_member add

Description

Add a member to members ignored by AutoMod.

Parameters:

Name Type Description Default
user OptionType.USER

member to be ignored by automod

required
Source code in extentions/automod.py
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
@AutoModSettings.subcommand('ignored_member', 'add', 'Make a member to be ignored by automod.')
@user()
async def AutomodAddIgnoredMember(self, ctx:InteractionContext, user: OptionType.USER):
    """
    /automod ignored_member add
    Description:
        Add a member to members ignored by AutoMod.

    Args:
        user (OptionType.USER): member to be ignored by automod
    """
    await ctx.defer(ephemeral=True)
    settings = await db.amConfig.find_one({"guild":ctx.guild.id})
    if settings is None:
        await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
    ignored_users = settings.ignored_users
    if ignored_users is None:
        ignored_users = list()
    if user.id in ignored_users:
        await ctx.send(f'{user}|{user.id} is already ignored.', ephemeral=True)
    ignored_users.append(user.id)
    await settings.save()
    users = [ctx.guild.get_member(id) for id in ignored_users]
    users = [f'{r}({r.id})' for r in users if r is not None]
    users = ' '.join(users)
    embed = Embed(description=f"Member {user}({user.id}) was added to members ignored by automod.")
    embed.add_field('Ignored Members', users)
    await ctx.send(embed=embed, ephemeral=True)

AutomodRemoveIgnoredMember(ctx, user) async

/automod ignored_member remove

Description

Remove a member from members ignored by AutoMod.

Parameters:

Name Type Description Default
user OptionType.USER

member to be removed from ignored members by automod

required
Source code in extentions/automod.py
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
@AutoModSettings.subcommand('ignored_member', 'remove', 'Remove a member from ignored members.')
@user()
async def AutomodRemoveIgnoredMember(self, ctx:InteractionContext, user: OptionType.USER):
    """
    /automod ignored_member remove
    Description:
        Remove a member from members ignored by AutoMod.

    Args:
        user (OptionType.USER): member to be removed from ignored members by automod
    """
    await ctx.defer(ephemeral=True)
    settings = await db.amConfig.find_one({"guild":ctx.guild.id})
    if settings is None:
       await db.amConfig(guild=ctx.guild.id, phishing=violation_settings, banned_words=violation_settings, banned_names=violation_settings).insert()
    ignored_users = settings.ignored_users
    if ignored_users is None:
        ignored_users = list()
    if user.id not in ignored_users:
        await ctx.send(f'{user}|{user.id} is not being ignored by automod.', ephemeral=True)
    ignored_users.remove(user.id)
    await settings.save()
    users = [ctx.guild.get_member(id) for id in ignored_users]
    users = [f'{r}({r.id})' for r in users if r is not None]
    users = ' '.join(users)
    embed = Embed(description=f"Member {user}({user.id}) was removed from members ignored by automod.")
    embed.add_field('Ignored Members', users)
    await ctx.send(embed=embed, ephemeral=True)

Ignored chanels, ignored roles, and ban/mute times are global across the automod system.