如何获取提到的用户的 ID (Discord.py)

exp*_*101 1 python-3.x discord.py

@bot.command()
async def id(ctx, a:str): #a = @user
Run Code Online (Sandbox Code Playgroud)

我如何获取命令中提到的用户的 ID,并将其输出为:

await ctx.send(id)
Run Code Online (Sandbox Code Playgroud)

Pat*_*ugh 6

使用转换器来获取User对象:

@bot.command(name="id")
async def id_(ctx, user: discord.User):
    await ctx.send(user.id)
Run Code Online (Sandbox Code Playgroud)

或者获取id作者的:

@bot.command(name="id")
async def id_(ctx):
    await ctx.send(ctx.author.id)
Run Code Online (Sandbox Code Playgroud)