Reputation: 308
I'm trying to figure out who invited a user when they join, but when I try to get the number of times an invite has been used I keep getting None
. Here's my code:
@client.event
async def on_ready(self):
global before_invites
before_invites = []
for guild in self.client.guilds:
for invite in await guild.invites():
invite = await self.client.get_invite(invite)
x = [invite.url, invite.uses, invite.inviter.id]
before_invites.append(x)
print(before_invites)
which then prints out [['http://discord.gg/xxxxxxx', None, 01234567890123456789], ['http://discord.gg/xxxxxxx', None, 01234567890123456789], ...]
So far I've double checked and the bot has all permissions in the server and made sure that there are invites for the server that have been used. Can only self accounts see invite uses?
Upvotes: 0
Views: 524
Reputation: 60994
The problem is that you're calling get_invite
instead of using the Invite
from Guild.invites
. get_invite
uses the GET Invite
endpoint of the Discord API, which only returns the invite object, not including it's metadata. By contrast, Guild.invites
uses the GET Channel Invites
endpoint, which does return the metadata objects.
Just use the invites from Guild.invites
directly:
@client.event
async def on_ready(self):
global before_invites
before_invites = []
for guild in self.client.guilds:
for invite in await guild.invites():
x = [invite.url, invite.uses, invite.inviter.id]
before_invites.append(x)
print(before_invites)
Upvotes: 1