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.
Watching the number of uses an invite has had, or for when they run out of uses and are revoked, is the only way to see how a user was invited to the server.
Discord.py show who invited a user