Get person who invited the discord bot discord.py

Question:

Is there any way to get the person who invited the bot to the server? My point is to dm that person to tell her what to do so things go smoothly and I don’t want the bot to just write it in a random text channel that everybody could see. Thanks in advance

Asked By: Lysander12 PT

||

Answers:

There isn’t any way yet to know who invited the bot.
What you can do is DM the Server Owner when its added to a Server.

Answered By: Just for fun

there is an actual way to get the user who invited the bot

    @commands.Cog.listener() 
    async def on_guild_join(self, guild: discord.Guild):
     async for entry in guild.audit_logs(limit=1, action=discord.AuditLogAction.bot_add):
      mem = entry.user
      if entry.target.id == self.bot.user.id:
        await mem.send("thank you for inviting me")

you can do it by checking the audit log

Answered By: south