首页 > 解决方案 > AttributeError:“NoneType”对象没有属性“发送”不和谐机器人

问题描述

我需要帮助让我的机器人工作

# Import Discord Package
import discord

# Client (our bot)
client = discord.Client()

@client.event
async def on_ready():
    # DO STUFF....
    general_channel = client.get_channel()

    await general_channel.send('yo')

# Run the client on the server
client.run('')

当我运行它时,我得到 AttributeError: 'NoneType' object has no attribute 'send' in terminal,如果你能修复它,那将不会出现在不和谐上

标签: python

解决方案


get_ 将返回 None 的常见原因是:a) 未找到通道 ID b) 机器人未连接 c) 在机器人启动之前调用 get_ 方法。

在您的情况下,有两个明显的失误

  1. get_channel 方法需要一个参数,它是通道 ID。 https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.get_channel

  2. 该机器人可能未登录,因为 client.run() 还需要一个令牌参数。client.run('your_token')


推荐阅读