如何检索不和谐用户的状态

时间:2021-07-29 01:41:08

标签: python discord.py

@bot.command(aliases=["stat"])
async def status(ctx, user: discord.Member = None):
    await ctx.message.delete()
    if user is None:
        user = ctx.author
    try:
        em = discord.Embed(description=discord.Status) 
        em.set_author(name="User Status", icon_url=user.avatar_url)
        await ctx.send(embed=em)
    except Exception as e:
        print(f"{Fore.RED}[ERROR]: {Fore.BLUE}{e}" + Fore.RESET)`#Printing Error

discord.Status Discord 文档说这是如何检索用户状态,但事实并非如此

1 个答案:

答案 0 :(得分:0)

discord.Status 是表示用户状态的类。您的 user 变量属于 discord.Member 类型,其中包含 status field

因此您可以使用 user.status 访问它。完整的代码如下所示:

@bot.command(aliases=["stat"])
async def status(ctx, user: discord.Member = None):
    await ctx.message.delete()
    if user is None:
        user = ctx.author
    try:
        em = discord.Embed(description=user.status) 
        em.set_author(name="User Status", icon_url=user.avatar_url)
        await ctx.send(embed=em)
    except Exception as e:
        print(f"{Fore.RED}[ERROR]: {Fore.BLUE}{e}" + Fore.RESET)`#Printing Error