discord - 如何使用 discord.py 在不和谐服务器的特定频道中获取所有聊天消息?
问题描述
我的机器人具有管理员权限,所以我只是想知道是否可以从 1 个频道获取所有消息,例如 #general。
解决方案
频道历史
这是可能的,有一个函数可以做到这一点:channel.history()
此函数可用于检索通道中发送的所有消息。但是,如果您要检索包含数千条消息的频道中的所有消息,则速度非常慢。
例子
此示例显示了如何检索在某个通道中发送的每条消息:
async def get_history_of_channel(channel):
messages = await channel.history(limit=None) # adding None lets us retrieve every message
for message in messages:
# do something with that message
print(message.content)
参考
推荐阅读
- r - 在R中获取月份作为数值
- docker - Kong Container 限制连接数
- node.js - Microsoft Bot Framework 使用 request.user 识别和问候不同的用户,但只获取最后添加的用户
- javascript - 在多个上运行相同的 JS 函数名称值
- c++ - 在多个类中使用相同的对象实例
- java - 如何解决我的 java netbean 编码错误?
- reactjs - 反应没有使用类中的状态更新组件
- javascript - D3.js 将行名附加到它
- keycloak - 403 Forbidden while access Leycloak rest API with a valid user credentials
- sql - Sql 查询 - 带条件分区子句的求和