python 如何修复AttributeError:“NoneType”对象没有属性“send”

eqqqjvef  于 2022-12-25  发布在  Python
关注(0)|答案(2)|浏览(337)

这样做的目的是尝试通过机器人程序将保存在计算机上的本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'
fwzugrvs

fwzugrvs1#

www.example.com的官方文档Discord.py说

**参数:**id(int)-要搜索的ID。
**返回:**返回的通道或None(如果未找到)。

这意味着提供的ID与任何服务器都不匹配,因此很可能是您键入错误或在代码中的某个地方意外修改了它

wj8zmpe1

wj8zmpe12#

await channel.send(file=file)
AttributeError: 'NoneType' object has no attribute 'send'

因此channelNone,所以错误是由以下原因引起的。

channel = client.get_channel(CHANNEL_ID)

我猜99%的CHANNEL_ID是一个str ing而不是一个int埃格...

相关问题