用户登录
用户注册

分享至

查找消息的作者

  • 作者: 请叫我风儿哥
  • 来源: 51数据库
  • 2023-02-01

问题描述

如果有人写?name (arg)",我希望我的机器人说出消息的作者+,你的名字是"+ arg.我找不到该消息的作者.

If someone writes "?name (arg)" I want my bot to say the author of the message + ", your name is" + arg. I can't find of the author of the message though.

@client.command()
async def name(their_name):
    await client.say("{0}, your name is {1}.".format("""author of the message goes here""", their_name))

推荐答案

要获取消息作者的姓名,您需要使用 上下文

To get the name of the author of the message, you will need to use context

@client.command(pass_context=True)
async def name(ctx):
    username = ctx.message.author.name
    ...
软件
前端设计
程序设计
Java相关