[英]How can i fix this :AttributeError: 'NoneType' object has no attribute 'strip
[英]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'
參數: id ( int ) – 要搜索的 ID。
返回:返回的通道,如果找不到則為
None
。
這意味着提供的 ID 與任何服務器都不匹配,因此很可能是您輸入錯誤或不小心在某處的代碼中修改了它
await channel.send(file=file)
AttributeError: 'NoneType' object has no attribute 'send'
所以channel
是None
,所以錯誤是由以下原因引起的。
channel = client.get_channel(CHANNEL_ID)
我猜 99% 的人認為CHANNEL_ID
是一個str
而不是一個int
......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.