python - 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,如果你能修复它,那将不会出现在不和谐上
解决方案
get_ 将返回 None 的常见原因是:a) 未找到通道 ID b) 机器人未连接 c) 在机器人启动之前调用 get_ 方法。
在您的情况下,有两个明显的失误
get_channel 方法需要一个参数,它是通道 ID。 https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.get_channel
该机器人可能未登录,因为 client.run() 还需要一个令牌参数。client.run('your_token')
推荐阅读
- elasticsearch - 用于全文搜索的弹性查询
- typescript - 是否可以从对象中提取函数参数类型作为元组?
- node.js - 从 https.request 获取正文
- node.js - 在开始对话之前保存数据
- python - 无法将所有 GPIO 引脚置于高 4 通道电机控制器
- java - Spring 集成:带有 SFTP 网关的 Http
- javascript - 渲染方法中的三元运算符
- python - python使用正则表达式根据前一行读取接下来的n行
- r - 用于配对 Wilcoxon 检验的带有 p 值的动画小提琴/箱线图
- flutter - 在 SingleChildScrollView 内垂直居中小部件