简体   繁体   中英

discord Python Anti Vanity

So im trying to make an anti vanity change as part of my bots anti-nuke but its not working and returning no errors. Here is the code:

         
    @commands.Cog.listener()
    async def on_guild_update(self, before, after):
      if before.premium_tier == 3:
        try:
          with open('whitelisted.json') as f:
            whitelisted = json.load(f)
          before_vanity = await before.vanity_invite()
          whitelistedUsers = str(whitelisted)
          after_vanity = await after.vanity_invite()
          if before_vanity != after_vanity:
            async for entry in after.audit_logs(limit=1, after=datetime.datetime.now() - datetime.timedelta(seconds = 3), action=discord.AuditLogDiff.vanity_url_code):
              if entry.user.id in whitelistedUsers or entry.user in whitelistedUsers:
                return
              if entry.target == before:
                try:
                    await entry.user.ban(reason="Lying\n・Unauthorized user changing vanity.")                    
                    session.patch(f"https://discord.com/api/v9/guilds/{after.id}/vanity-url/{before_vanity}")
                except Exception as error:
                  if isinstance(error, discord.Forbidden):
                    return
                  else:
                    return print(f"{Fore.RED}[Anti Error]: Vanity Protection ({after.name}){Fore.RESET}")
        except Exception as error:
            print(f"{Fore.RED}[Anti Error]: {error} | Anti-Vanity. ({after.name}){Fore.RESET}") 


I also made sure i was unwhitelisted while testing but still nothing happened.

If no errors are shown in your code, maybe you badly overwrote the on_command_error or on_error functions in the cog or in the bot, you should add a default case that re-raise the exception if it was not processed by the function

And for the issue, I'm suspecting that if before.premium_tier == 3: should be if before.guild.premium_tier == 3:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM