Python 如何使用discord.py创建一个bot来读取一条消息在文本通道中写入了多少次?
这是我的代码: (我使用python 3.7) 我尝试了我所有的项目,我知道除了这一部分,一切都正常:Python 如何使用discord.py创建一个bot来读取一条消息在文本通道中写入了多少次?,python,search,bots,discord.py,history,Python,Search,Bots,Discord.py,History,这是我的代码: (我使用python 3.7) 我尝试了我所有的项目,我知道除了这一部分,一切都正常: async for msg in client.logs_from(message.channel, limit=500): await asyncio.sleep(3) if msg.content.lower() == message.content.lower(): counter = counter + 1 result =
async for msg in client.logs_from(message.channel, limit=500):
await asyncio.sleep(3)
if msg.content.lower() == message.content.lower():
counter = counter + 1
result = "" + counter
我不知道如何使用来自的日志,我还尝试使用message.channel.history如下:
counter = 0
async for m in message.channel.history(limit=500):
await asyncio.sleep(3)
if message.content.lower() == m.content.lower():
counter = counter + 1
result = "" + counter
还有,我如何在所有文本频道的历史记录中搜索
我想我在使用wait和async时失败了,有人能给我一些建议来解决这个问题吗?我应该使用不同的方法来实现这一点吗?为什么历史记录中的每条消息都要等待3秒钟?这将需要几个小时才能运行。@PatrickHaugh我在几次尝试后添加了这一点,因为我想看看是否需要更多的时间来运行日志,但即使没有这一点,它仍然无法工作。您收到的错误消息到底是什么?乍一看,
result=“”+counter
也会引起问题,您应该做result=str(counter)
而不是将result=“”+counter
更改为result=str(counter)
,我删除了等待异步。睡眠(3)
,正如您建议的那样+I更改了message.channel.history中的条件()循环,现在它工作得很好。谢谢@PatrickHaugh
counter = 0
async for m in message.channel.history(limit=500):
await asyncio.sleep(3)
if message.content.lower() == m.content.lower():
counter = counter + 1
result = "" + counter