johnny mcdangerface
johnny mcdangerface

Reputation: 11

Python Discord.py - discord.Message.author outputting a strange result

I'm new to the Discord API and am trying to make my own bot. I'm trying to get it to record the nickname (not username) of the person who sent the message "-clan". Example:

Surge - Today at 15:01
-clan

This should output the result "Surge".

However, instead, it outputs this:

surge epic bot!!!BOT - Today at 15:01
<member 'author' of 'Message' objects>

I can't figure out why it's doing that, so some input would be greatly appreciated.

My current code:

@client.event
async def on_message(message):
    if message.content.startswith("-clan"):
        await client.send_message(message.channel, discord.Message.author)

Thank you!

Upvotes: 0

Views: 7488

Answers (3)

Dec0Dedd
Dec0Dedd

Reputation: 350

To send a message author use just message.author.

Upvotes: 0

mental
mental

Reputation: 836

await client.send_message(message.channel, discord.Message.author) Will send the __repr__ of the author object to the channel the message is in.

What you want instead is await client.send_message(message.channel, 'Surge!') Since the second argument is the message you want to send and the first is the destination.

Also it looks like you are placing your commands in a big on_message event switch case, if im not mistaken and you are; I do not reccomend this. Instead use the commands extension, the async branch of discord.py does not document this well and is mostly out of use, first i reccomend you use the rewrite branch of discord.py and read the docs about the commands extension here.

Upvotes: 0

ADug
ADug

Reputation: 314

Just do discord.Message.author.name ,name is an attribute of the discord.Author class.

Upvotes: 1

Related Questions