簡體   English   中英

通過 Discord bot (Python) 發送文件

[英]Issue sending file via Discord bot (Python)

if message.content.upper().startswith("!HEADPATS"):
    time.sleep(1)
    with open('tenor.gif', 'rb') as picture:
      await client.send_file(channel, picture)

我已經啟動並運行了我的不和諧機器人(一切都是用 python 編寫的)。 我試圖讓機器人根據命令“!headpats”在頻道中發送 .gif。 文件已上傳並且代碼編譯正常,但是當通過 discord 調用 !headpats 命令時,編譯器將其吐出...

File "main.py", line 106, in on_message
    await client.send_file(channel, picture)
NameError: name 'channel' is not defined

您在on_message事件中獲得的只是收到的Message 如果您想推斷它所在的channel它所在的server 、編寫它的author等,則必須通過message解析這些屬性。 message.channelmessage.server等)。

如果您使用的是discord.ext.commands擴展,那么您首先需要將消息解析為調用上下文的屬性:例如ctx.message.channel

暫無
暫無

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

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