I am currently trying to figure out a way to know who invited a user. From the official docs, I would think that the member class would have an attribute showing who invited them, but it doesn't. I have a very faint idea of a possible method to get the user who invited and that would be to get all invites in the server then get the number of uses, when someone joins the server, it checks to see the invite that has gone up a use. But I don't  know if this is the most efficient method or at least the used method.
In Discord, you're never going to 100% sure who invited the user.
Using Invite, you know who created the invite.
Using on_member_join, you know who joined.
So, yes, you could have to check invites and see which invite got revoked. However, you will never know for sure who invited since anyone can paste the same invite link anywhere.
Discord.py show who invited a user