问题描述
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命令时,编译器会将其吐出...
I've got my discord bot up and running (everything's written in python). I'm trying to get the bot to send a .gif in the channel upon the command "!headpats". The file is uploaded and the code compiles fine, but when the !headpats command is called via discord, the compiler spits this out...
File "main.py", line 106, in on_message
await client.send_file(channel, picture)
NameError: name 'channel' is not defined
推荐答案
您在 on_message
事件中获得的所有东西是。如果要推断频道
所在的位置,请选择服务器
所在的频道,作者
是谁编写的,等等,您必须通过消息
解析这些属性。 ( message.channel
, message.server
,依此类推)。
All you get inside your on_message
event is the Message
that was received. If you want to infer the channel
it's in, the server
it's on, the author
who wrote it, etc., you'll have to resolve those attributes through the message
. (message.channel
, message.server
, and so on).
如果使用的是 discord.ext.commands
扩展名,则首先需要将消息解析为: ctx.message.channel
。
If you're using the discord.ext.commands
extension, then you first need to resolve the message as an attribute of the invocation context: ctx.message.channel
, for example.
这篇关于通过Discord机器人(Python)发送文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!