Finding author of a message

≡放荡痞女 提交于 2020-01-30 07:57:25

问题


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))

回答1:


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
    ...



回答2:


You can also use User.display_name, which will try to to use the users server-specific nickname, but will fall back to the general username if that is not found:

@client.command(pass_context=True)
async def name(ctx):
    username = ctx.message.author.display_name



回答3:


To get the name of the author of the message you can use the:

message.author.id


来源:https://stackoverflow.com/questions/46611016/finding-author-of-a-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!