【问题标题】:AttributeError: 'NoneType' object has no attribute 'send' discord botAttributeError:“NoneType”对象没有属性“发送”不和谐机器人
【发布时间】:2021-01-22 13:26:13
【问题描述】:

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

# 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


    【解决方案1】:

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

    在你的情况下有 2 个明显的失误

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

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

    【讨论】:

    • 我取出了服务器 ID 和令牌,这样我就不必重置机器人令牌
    • 酷,通道 ID 的有效参数是一个 int。 get_channel('444') 无效,而 get_channel(444) 有效
    • 让我在第二篇文章中给你看一个屏幕截图,这样你就可以理解我的错误,因为我认为它告诉我走一条路,而你告诉我走另一条路
    • [在此处输入图像描述][1] [1]:i.stack.imgur.com/LUDpD.jpg这是我在终端中的错误
    • 评估此“general_channel = client.get_channel()”时,返回值为 None。因此,我希望您检查是否已将正确的数据类型传递给 get channel 函数。您可能确实传递了正确的通道 ID,但不是函数所期望的正确类型,即 INT
    猜你喜欢
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 2021-02-22
    • 2022-10-20
    • 2021-11-12
    • 2019-01-01
    相关资源
    最近更新 更多