【发布时间】:2017-11-13 05:59:50
【问题描述】:
我目前正在尝试使用 python 制作一个从服务器上的频道收集统计信息的机器人。我想查看用户在某个频道中发送了多少条消息。目前我的代码如下所示:
if message.content.startswith('!stat'):
mesg = await client.send_message(message.channel, 'Calculating...')
counter = 0
async for msg in client.logs_from(message.channel, limit=9999999):
if msg.author == message.author:
counter += 1
await client.edit_message(mesg, '{} has {} messages in {}.'.format(message.author, str(counter), message.channel))
这基本上可以满足我的要求,但是计算所有消息的过程非常缓慢。是否有其他方法可以达到相同的结果但响应速度更快?
【问题讨论】: