discord.py logs_from 不工作

discord.py logs_from not working

我正在尝试从服务器获取大量消息,因此我正在制作测试脚本,但 logs_from() 无法正常工作,我不知道我是否在使用它是错误的还是什么,我正在使用 python 3.5,以及 pypi

上最新版本的 discord.py
@client.event
@asyncio.coroutine
def on_message(message):
    number = 200
    x = client.logs_from(message.channel, limit = number)
    print(x[1])

我得到了错误

TypeError: 'LogsFromIterator' object does not support indexing

Client.logs_from 是协程,这意味着您必须先等待它。它还 returns 一个迭代器,而不是一个列表,所以你应该遍历它,而不是索引它。

Python 3.5 例子:

async def get_logs_from(channel):
    async for m in client.logs_from(channel):
        print(m.clean_content)

Python 3.4 例子:

@asyncio.coroutine
def get_logs_from(channel):
    logs = yield from client.logs_from(channel):
    for m in logs:
        print(m.clean_content)