invite.uses 返回 None

invite.uses returning None

我试图弄清楚是谁在用户加入时邀请了他们,但是当我尝试获取使用邀请的次数时,我一直得到 None。这是我的代码:

 @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)

然后打印出 [['http://discord.gg/xxxxxxx', None, 01234567890123456789], ['http://discord.gg/xxxxxxx', None, 01234567890123456789], ...]

到目前为止,我已经仔细检查过,机器人拥有服务器中的所有权限,并确保有已使用的服务器邀请。只有自己的帐号才能看到邀请使用吗?

问题是您调用 get_invite 而不是使用 Guild.invites 中的 Inviteget_invite 使用 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 端点,它 return 元数据对象。

直接使用来自Guild.invites的邀请:

@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)