python - 如何让 discord.py 机器人通过控制台向特定频道发送消息
问题描述
discord.py - 通过控制台发送消息- 这个问题已经过时,所以我将尝试重新询问,因为那里提供的解决方案不起作用。
我希望我的不和谐机器人通过控制台中的输入向特定频道发送消息。我的代码如下:
channel_entry = 614001879831150605
msg_entry = 'test'
@client.event
async def send2():
channel = client.get_channel(channel_entry.get)
await channel.send(msg_entry)
我收到以下错误:
AttributeError: 'NoneType' object has no attribute 'send'
任何帮助表示赞赏。
解决方案
您不需要将其注册为 a
client.event
,因为您不会对 Discord 中发生的事情做出反应,这意味着不需要装饰器。我不得不说我很困惑为什么你
get
在channel_entry.get
. 只需使用整数本身。这可能是您错误的根源。因为你没有向它传递一个整数,client.get_channel
所以它返回一个 None 对象,因为没有找到通道。文件
工作示例:
channel_entry = 614001879831150605
msg_entry = 'test'
async def send_channel_entry():
channel = client.get_channel(channel_entry)
await channel.send(msg_entry)
还要确保您安装了最新版本的 discord.py。
推荐阅读
- google-maps - 使用集群标记离子 3 时 INFO_cLICK 事件未触发
- php - 是否存在安全漏洞,包括换个角度看
- jsp - 我如何使用一些jsp页面将数据插入数据库表?
- javascript - 仅创建 mp3 格式的 HTML/Javascript 音频播放器
- excel-formula - 需要 Excel 公式帮助 需要
- php - 如何在 Laravel 中打印数据以列格式显示的表格?
- javascript - JavaScript - 函数外的空数组
- php - Mysql Query 如果我们先调用两次获取计数然后列出,则需要更多时间
- java - 无法用 Java 实例化类型
- java - 停止、暂停和恢复由 Spring MVC 控制器中的队列运行的循环