由于在命令后提及而更改响应

时间:2021-01-12 01:21:44

标签: python discord.py

所以我有一个名为 p!profile 的命令,它发送用户的个人资料。我希望有人执行命令 p!profile @someone 我的机器人会发送此人的个人资料。 我不是世界上最好的编码员,抱歉。另外,感谢过去帮助过我的人<3

@client.command
async def profile(ctx, mention):
  if ctx.mention == ctx.author:
        #code
  else:
        #code

1 个答案:

答案 0 :(得分:1)

您可以使用 discord.Member 代替 mention 作为 arg。如果执行您的 None 命令的人没有提及任何人,您可以最初将其定义为 p!profile

@client.command()
async def profile(ctx, user:discord.Member=None):
    if user == None or user == ctx.author:
        user = ctx.author # converts user to ctx.author if user is None or the person mentioned themselves
    else:
        # other code here

我以前做过这样的命令,这是上面的工作。 Not mentioning someone and it gives you ctx.author Mentioning someone and it gives you user