I'm making a discord bot that kicks bots that are invited to the server who were not invited by users with specific roles. I am struggling to find out who invited a bot to the server. I ran a few tests and came to the conclusion that an invite code/link is not created when someone invites a bot. I know I can see who invited a bot in the AuditLogs but I want to kick a bot automatically if it is invited by an admin who should not be able to invite them.
One way to solve this issue is to just not allow people other than admins to invite people to the server. However, if you want people to be ale to invite others, just not bots, here is what you can do: When a bot joins the server, you can use your bot to check iterate over the audit logs and check if the action is an invite and the target is the bot they you can check who invited the bot. From there on just check if who invited the bot is an admin, if not, kick the bot.
Discord.py I want to have something in my code that gives me the person who invited a bot