Tyler Silva
Tyler Silva

Reputation: 421

discord.py logs_from not working

i am trying to get a lot of messages from a server, so i am making a test scripts, and the logs_from() is not working how i think it should, i dont know if im using it wrong or what, i am using python 3.5, and the most recent version of discord.py on pypi

@client.event
@asyncio.coroutine
def on_message(message):
    number = 200
    x = client.logs_from(message.channel, limit = number)
    print(x[1])

and i get the error

TypeError: 'LogsFromIterator' object does not support indexing

Upvotes: 2

Views: 4415

Answers (1)

Sam Rockett
Sam Rockett

Reputation: 3205

Client.logs_from is a coroutine, meaning you must first await it. It also returns an iterator, not a list, so you should iterate through it, instead of indexing it.

Python 3.5 example:

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

Python 3.4 example:

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

Upvotes: 1

Related Questions