[英]How can I fix, AttributeError: 'NoneType' object has no attribute 'send'
Aim of this is to try get a local image saved on your computer sent to a discord channel via a bot这样做的目的是尝试通过机器人将保存在计算机上的本地图像发送到不和谐频道
# Create an Intents object with the `messages` attribute set to True
intents = discord.Intents(messages=True)
# Create the client with the specified intents
client = discord.Client(intents=intents)
@client.event
async def on_ready():
# When the bot is ready, send the image to the specified channel
channel = client.get_channel(CHANNEL_ID)
with open(r"file path", 'rb') as f:
file = discord.File(f)
await channel.send(file=file)
client.run(TOKEN)
Traceback (most recent call last):
File "C:\Python\Python39\lib\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "path", line 39, in on_ready
await channel.send(file=file)
AttributeError: 'NoneType' object has no attribute 'send'
The offical documentation for Discord.py says Discord.py 的官方文档说
Parameters: id ( int ) – The ID to search for.
参数: id ( int ) – 要搜索的 ID。
Returns: The returned channel or
None
if not found.返回:返回的通道,如果找不到则为
None
。
This means that the ID supplied does not match any server, so most likely you mistyped it or accidentally modified it in code somewhere这意味着提供的 ID 与任何服务器都不匹配,因此很可能是您输入错误或不小心在某处的代码中修改了它
await channel.send(file=file)
AttributeError: 'NoneType' object has no attribute 'send'
So channel
is None
, so the error was caused by the following.所以
channel
是None
,所以错误是由以下原因引起的。
channel = client.get_channel(CHANNEL_ID)
I guess 99% that CHANNEL_ID
is a str
ing and not an int
eger...我猜 99% 的人认为
CHANNEL_ID
是一个str
而不是一个int
......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.