这样做的目的是尝试通过机器人程序将保存在计算机上的本Map像发送到不和谐频道
# 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'
2条答案
按热度按时间fwzugrvs1#
www.example.com的官方文档Discord.py说
**参数:**id(int)-要搜索的ID。
**返回:**返回的通道或
None
(如果未找到)。这意味着提供的ID与任何服务器都不匹配,因此很可能是您键入错误或在代码中的某个地方意外修改了它
wj8zmpe12#
因此
channel
是None
,所以错误是由以下原因引起的。我猜99%的
CHANNEL_ID
是一个str
ing而不是一个int
埃格...