如何在服务器中的命令后不输入 id 的情况下提及用户

时间:2021-06-03 23:53:57

标签: discord.py

@client.command()
async def status(current, content: str):
    status = None
    for member in current.guild.members:
        if str(member.id) == content:
            status = member.status
            break
    if status == discord.Status.online:
        online_embed = discord.Embed(
            title="awa is online", description="", color=0xF6E5E5
        )
        await current.send(embed=online_embed)

我每次都必须做 #status [user id],有没有办法让它只 #status?

1 个答案:

答案 0 :(得分:0)

在命令中获取成员对象的最简单方法之一(允许您使用用户的 ID、他们的姓名等)是使用他们提供的转换器。

@client.command()
async def test(current, member: discord.Member=None):
    if member == None: # if no member is provided..
        member = current.author # ..make member the author
    await current.send(f"Hello {member.mention}!")

Above code working

其他类似问题