Michael Duffett
Michael Duffett

Reputation: 85

Discord.py - Finding information about the sender

I am making a simple discord bot and am trying to find out the channel and sender of a message, so for example when someome types d!salute blah it will reply with "<SENDER> saluted blah!", accompanied by an image. I currently only really know how to use client.say, which finds the channel for me. What I want to know is how to retrieve both the channel a message is sent from and also the sender of the command. Thanks

Upvotes: 3

Views: 9773

Answers (1)

Wright
Wright

Reputation: 3424

You need to pass context so you can access the message object.

@client.command(pass_context = True) #passing context
async def salute(ctx): #context gets passed into the first parameter
    print(str(ctx.message.author))
    print(str(ctx.message.channel)
    print(str(ctx.message.content))

And so on, you can find out more on the message object at The docs

Upvotes: 5

Related Questions