如何获取提及用户的 ID (Discord.py) [英] How to get ID of a mentioned user (Discord.py)

查看:118
本文介绍了如何获取提及用户的 ID (Discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@bot.command()
async def id(ctx, a:str): #a = @user

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

how would I get the ID of a user mentioned in the command, and output it as:

await ctx.send(id)

推荐答案

使用 converter 获取 User 对象:

Use a converter to get the User object:

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

或者获取作者的id:

@bot.command(name="id")
async def id_(ctx):
    await ctx.send(ctx.author.id)

这篇关于如何获取提及用户的 ID (Discord.py)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆