Python 3.x discord.py从名称#鉴别器获取成员实例

Python 3.x discord.py从名称#鉴别器获取成员实例,python-3.x,discord.py,Python 3.x,Discord.py,我有一个用户名为“somename#1111”的字符串user=我怎么能提到他?(我从google sheets中得到了这个名字,这就是为什么它是一个字符串) 我试过: @client.command() async def mention(ctx): user : discord.Member = 'somename#1111' await ctx.send(f"{user.mention} hello!") 但是它不起作用虽然这种方法有效,但我建议切换到保存用户ID,而不是

我有一个用户名为“somename#1111”的字符串
user=
我怎么能提到他?(我从google sheets中得到了这个名字,这就是为什么它是一个字符串)

我试过:

@client.command()
async def mention(ctx):
    user : discord.Member = 'somename#1111'
    await ctx.send(f"{user.mention} hello!")

但是它不起作用

虽然这种方法有效,但我建议切换到保存用户ID,而不是用户名+鉴别器,因为用户ID是常量,但用户可以更改其名称和鉴别器

@client.command()
异步定义提及(ctx):
user=discord.utils.get(ctx.guild.members,name=“somename”,discriminator=“1111”)
等待ctx.send(f“{user.antify}hello!”)
并且使用ID:

@client.command()
异步定义提及(ctx):
user=ctx.guild.get_成员(11223344566778899)#在那里替换用户ID
尝试:
等待ctx.send(f“{user.antify}hello!”)
除:
等待ctx.send(“对不起,该用户已离开服务器!”)

参考文献:

  • -“返回找到的第一个与提供的名称匹配的成员。”

我没有使用user.note,但我要做的是获取用户id,然后像这样提及它们:

wait ctx.send(f'hello!')

另外,您是否成功地使消息编辑命令按您所希望的方式工作?太好了!很高兴听到:)您还可以使用
f'
,这是提及的原始格式