为什么在这段代码上出现AttrributeError?

问题描述

当我运行以下代码行时,出现错误“ AttributeError:'nonetype'对象没有属性'send'”: 我该如何解决

    if Now.weekday() == 3:
        if thursday_lunch_time.shift(minutes=1).time() > Now.time() > thursday_lunch_time.time():
            print(f"Got channel {channel}")
            await channel.send(random.choice(list_warning))
            await asyncio.sleep(65)

解决方法

机器人无法获取频道,因此其“无”且您正在执行channel.send的意思是None.send,这就是您收到该错误的原因

确保该漫游器有权读取该频道的消息,并传递正确的频道ID或频道名称。