簡體   English   中英

在print命令中打印字符串時出現Discord.py錯誤

[英]Discord.py error when printing string in print command

我正在嘗試創建一個在Discord服務器中的某人發送消息時將消息打印到控制台的bot 這是我的代碼:

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

但是,當我運行此代碼時,它給了我一個錯誤。

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

嘗試這個:

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

您可以嘗試以下方法:

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

說明:在進行string concatenation兩個操作數都應為str類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM