Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding author of a message

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))
like image 573
TRSI Avatar asked Oct 06 '17 17:10

TRSI


2 Answers

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
    ...
like image 186
Sam Rockett Avatar answered Oct 13 '22 12:10

Sam Rockett


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
like image 44
Patrick Haugh Avatar answered Oct 13 '22 11:10

Patrick Haugh