[英]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.