How to discord.Invite (see how many members in a given invitation)?

I'm working on a bot for Discord, but I'm having trouble making an accountant of invitations (people who enter a certain invitation)

In this way, it always returns None

    invite = await client.invites_from(message.channel.server)
        for x in invite:
    if x.inviter == message.author:
        uses_link = await client.get_invite(x)
        print(uses_link.uses) # This returns None

Upvotes: 1

Views: 1657

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 61063

The Client.get_invite coroutine accesses the GET Invite endpoint of the Discord API (See the source code). That endpoint seems to return a Discord Invite object. Critically, that object doesn't include the Invite metadata object which is where the Invite.uses field comes from.

Thankfully, the Client.invites_from coroutine returns a list of Invite objects that are calculated using the Invite metadata (from the GET Guild Invites endpoint). You can just use those directly.

invites = await client.invites_from(message.channel.server)
for invite in invite:
    if invite.inviter == message.author:
        print(invite.uses)

Upvotes: 1

Related Questions