【问题标题】:Issue sending file via Discord bot (Python)通过 Discord bot (Python) 发送文件问题
【发布时间】:2019-02-22 21:37:52
【问题描述】:
if message.content.upper().startswith("!HEADPATS"):
    time.sleep(1)
    with open('tenor.gif', 'rb') as picture:
      await client.send_file(channel, picture)

我的 discord 机器人已经启动并运行(一切都是用 python 编写的)。我试图让机器人根据命令“!headpats”在频道中发送.gif。文件已上传并且代码编译正常,但是当通过不和谐调用 !headpats 命令时,编译器会将其吐出...

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

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

您在on_message 事件中得到的只是收到的Message。如果您想推断它所在的channel、它所在的server、编写它的author 等等,您必须通过message 解析这些属性。 (message.channelmessage.server 等等)。

如果您使用的是discord.ext.commands 扩展,那么您首先需要将消息解析为invocation context 的属性:例如ctx.message.channel

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-07
    • 2020-08-21
    • 2021-04-05
    • 2020-11-07
    • 2018-11-24
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    相关资源
    最近更新 更多