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

No Entry Log Were Logged / Event was not Triggered When the integration was updated in a particular guild #9695

Closed
3 tasks done
GauravDev1921 opened this issue Dec 25, 2023 · 4 comments
Labels
unconfirmed bug A bug report that needs triaging

Comments

@GauravDev1921
Copy link

GauravDev1921 commented Dec 25, 2023

Summary

Fix Audit log Entry of Integration Create Which Gives No Log in Return

Reproduction Steps

i HAVE DROPPED THE SNIPPET OF THE CODE BELOW ALSO IF THERES SOMETHING WRONG FROM MY SIDE PLEASE CORRECT ME OUT

Minimal Reproducible Code

import discord
import aiohttp
import random
import logging
from discord.ext import commands
import asyncio
import os
 
role_id_to_check = 1188171185939304541

class BanCog(commands.Cog):
    def __init__(self, bot):
        self.client = bot
        self.headers = {"Authorization": ""}
        os.system('cls' if os.name == 'nt' else 'clear')
        print('[DEBUG] --> INTEGERATION AUDIT LOGGER LOADED')
        

    @commands.Cog.listener()
    async def on_audit_log_entry_create(self, guild):
        anti = 'on'
        reason = "Creating Integration | Not Whitelisted"

        async for entry in guild.audit_logs(limit=1, action=discord.AuditLogAction.integration_update):
            user = entry.user.id
            api = random.randint(8, 9)

            if entry.user.id == 893478038107488276:
                return
            elif entry.user == guild.owner or role_id_to_check in [role.id for role in entry.user.roles] or anti == "off":
                pass
            else:
                if entry.action == discord.AuditLogAction.integration_update:
                    async with aiohttp.ClientSession(headers=self.headers) as session:
                        response = await session.put(f"https://discord.com/api/v{api}/guilds/{guild.id}/bans/{user}", json={"reason": reason})
                        if response.status in (200, 201, 204):
                            print("Successfully banned %s" % (user))
                        else:
                            print("Failed to ban %s" % (user))
                            logging.error(await response.text())


async def setup(bot):
    await bot.add_cog(BanCog(bot))                                                                                  








-----------------------------------------------------------------------------------------------
                                 Bot Login Code

------------------------------------------------------------------------------------------------



import discord
from discord.ext import commands
import os
import asyncio

bot_token = ''

bot = commands.AutoShardedBot(command_prefix="+",intents=discord.Intents.all(),case_insensitive=True,strip_after_prefix=True,replied_user=False,shard_count=1, sync_commands_debug= True, sync_commands=True)
bot.remove_command('help')




@bot.event
async def on_ready():
    print(f'[DEBUG] Logged in as {bot.user} (ID: {bot.user.id})')





async def main():
    await bot.load_extension('anti_cog')
    await bot.start(bot_token)

if __name__ == "__main__":
    asyncio.run(main())

Expected Results

USER SHOULD BE LOGGED / BANNED BUT NO AUDIT LOG ENTRY WAS LOGGED THUS THIS MADE THE REASON TO BREAK THE FLOW OF WHOLE EVENT

Actual Results

NONE THERE WERE NO ACTION BEING UNDERTAKEN BY THE CODE WHICH I HAVE SHOWN

Intents

discord.Intents.all()

System Information

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

Nothing just i want to say is this problem from discord api side or a bug into dpy wrapper

@GauravDev1921 GauravDev1921 added the unconfirmed bug A bug report that needs triaging label Dec 25, 2023
@ika2kki
Copy link
Contributor

ika2kki commented Dec 25, 2023

Hi, the issue is that the logging module doesn't have any handlers set up so you won't get any output.
Running the bot with bot.start() means setting up logging is up to you - to quickly add a basic logging setup you can use the setup_logging() utility, for example:

async def main():
    await bot.load_extension('anti_cog')
    await bot.start(bot_token)

if __name__ == "__main__":
    discord.utils.setup_logging()
    asyncio.run(main())

discord.py handles this behavior for you when you run the bot with bot.run(). For more details you can visit this page: https://discordpy.readthedocs.io/en/stable/logging.html

In the future, please consider asking questions in the discord.py server or in the discussions tab with the Q/A tag.

@itslychee
Copy link

This definitely seems like a code issue rather than an issue with the library, but I'd like to point out a few things surrounding your code.

  • You should not be creating a manual HTTP request via aiohttp over the library's methods as unlike aiohttp, the library handles ratelimiting that may come from Discord. Use the Guild.fetch_ban method instead!
  • Add some print calls around your code so you can see if it's a problem with one of your conditionals
  • Don't use remove_command to remove the default help command, pass help_command=None to the bot constructor.
  • replied_user goes inside the allowed_mentions value with AllowedMentions as its type.
  • sync_commands_debug= True, sync_commands=True this is pointless
  • anti = 'on' Use a boolean!

And consider using an external file for placing your token in!

@tailoric
Copy link
Contributor

Another problem with your code
on_audit_log_entry_create
Does not get a guild object but a AuditLogEntry
So your guild.audit_logs call is invalid because it is not a guild object.
Also just think about it why would you need to fetch an audit log entry in the event that is listening for the creation of an audit log entry.

@GauravDev1921
Copy link
Author

Allright Thanks !

@Rapptz Rapptz closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

5 participants