简体   繁体   English

我该如何修复,AttributeError: 'NoneType' 对象没有属性 'send'

[英]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.所以channelNone ,所以错误是由以下原因引起的。


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.

相关问题 我该如何解决这个问题:AttributeError: 'NoneType' object has no attribute 'strip - How can i fix this :AttributeError: 'NoneType' object has no attribute 'strip 我该如何解决这个 AttributeError: 'NoneType' object has no attribute 'text'? - How do i fix this AttributeError: 'NoneType' object has no attribute 'text'? 如何修复 AttributeError: 'NoneType' object 没有属性 'lower'? - How do i fix AttributeError: 'NoneType' object has no attribute 'lower'? AttributeError: 'NoneType' object 没有属性 'setDelegate_' 我该如何解决这个问题? - AttributeError: 'NoneType' object has no attribute 'setDelegate_' how can I fix this? 我该如何解决 AttributeError 'NoneType' object has no attribute 'write' - how can i solve AttributeError 'NoneType' object has no attribute 'write' 如何修复 AttributeError: 'NoneType' 对象没有属性 'click' - How to fix AttributeError: 'NoneType' object has no attribute 'click' 如何修复AttributeError:'NoneType'对象没有属性'theme_cls' - How to fix AttributeError: 'NoneType' object has no attribute 'theme_cls' 如何修复“”AttributeError: 'NoneType' 对象没有属性 'app' - How to fix ""AttributeError: 'NoneType' object has no attribute 'app' 如何修复:AttributeError: 'NoneType' object 没有属性 'group' - How to fix: AttributeError: 'NoneType' object has no attribute 'group' “如何解决'AttributeError:'NoneType'对象在Python中没有属性'tbody'错误? - "How to fix 'AttributeError: 'NoneType' object has no attribute 'tbody'' error in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM