简体   繁体   中英

Discord.py error when printing string in print command

I'm trying to make a bot that prints a message to the console whenever someone in the Discord server sends a message. This is my code:

@client.event
async def on_message(message):
    print(message.author + ' sent a message.')

However, when I run this code it gives me an error.

TypeError: unsupported operand type(s) for +: 'Member' and 'str'

尝试这个:

print(str(message.author) + ' sent a message.')

You can try this:

@client.event
async def on_message(message):
     print(str(message.author) + ' sent a message.')

Explanation: As you are doing string concatenation both operands should be of type str

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM