Skip to content
Advertisement

Discord.py get uses and author from an invite

I would like to get all the invites from a discord server. I get all the invite but I want to get the author and the uses from it. Everything works just fine except the guild.uses.

Tried to embed the things from the discord API.

“””From discord api https://discordpy.readthedocs.io/en/latest/api.html

Attribute & Method

max_age abc.GuildChannel.invites(), Guild.invites()

max_uses abc.GuildChannel.invites(), Guild.invites()

created_at abc.GuildChannel.invites(), Guild.invites()

temporary abc.GuildChannel.invites(), Guild.invites()

uses abc.GuildChannel.invites(), Guild.invites()

approximate_member_count Client.fetch_invite()

approximate_presence_count Client.fetch_invite() “””

@client.event
async def on_ready():
    print("ready")
    for guild in client.guilds:
        x = await guild.invites()
        print(x)
        uses = guild.uses
        print(uses)
    

Advertisement

Answer

Simply use the Invite.inviter and Invite.uses attributes

for guild in client.guilds:
    invites = await guild.invites()

    for x in invites:
        print(f"Total uses: {x.uses} Created by: {x.inviter}")
Advertisement