簡體   English   中英

我該如何修復,AttributeError: 'NoneType' 對象沒有屬性 'send'

[英]How can I fix, AttributeError: 'NoneType' object has no attribute 'send'

這樣做的目的是嘗試通過機器人將保存在計算機上的本地圖像發送到不和諧頻道

# 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'

Discord.py 的官方文檔

參數: id ( int ) – 要搜索的 ID。

返回:返回的通道,如果找不到則為None

這意味着提供的 ID 與任何服務器都不匹配,因此很可能是您輸入錯誤或不小心在某處的代碼中修改了它

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

所以channelNone ,所以錯誤是由以下原因引起的。


channel = client.get_channel(CHANNEL_ID)

我猜 99% 的人認為CHANNEL_ID是一個str而不是一個int ......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM