2017-10-06 116 views
1

如果有人写“?name(arg)”我想让我的机器人说消息的作者+“,你的名字是”+ arg。 虽然我找不到消息的作者。查找作者的消息

<!-- language: lang-py --> 
@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

得到消息的作者的名字,你将需要使用context

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

为了让你可以使用该消息的作者的名字:

message.author.id 
+0

我试过这段代码,它说消息没有定义,所以我在代码的顶部定义了消息,现在它说str没有属性作者。 – TRSI