即使用户有硝基,它也不会返回 None
@bot.command(name="nitro")
async def has_nitro(ctx, user_id: int):
user = await ctx.guild.fetch_member(user_id)
if user:
nitro_status = 'Yes' if user.premium_since else 'No'
await ctx.send(f"{user.name} has nitro: {nitro_status}")
else:
await ctx.send("User not found in this server.")
discord.py 不会公开此信息,因为 Discord API 并未真正公开它。
premium_type
对象上有一个已记录的
User
字段,但它需要 identity
OAuth 范围。实际上,这意味着您无法从典型的机器人获取此信息。您需要构建一个通过 OAuth2 使用 Discord 进行身份验证的应用程序,并且用户明确需要授予您的应用程序代表他们访问信息的权限。
根据此讨论,Discord 目前没有计划删除
identity
范围要求。