Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get an array of all the messages from a text channel in discord.py?

I have the channel object, and I've tried

mess = channel.history(limit=200)

but mess is a HistoryIterator object and does not contain any messages in its mess.messages object (size = 0). There are messages in the channel, so it shouldn't say the size is 0.

I've also tried:

mess = client.logs_from(channel, limit=200)

but PyCharm tells me that client has no logs_from function.

Is there an easy way to get all of the messages from a text channel in an array?

like image 655
Lambda1010 Avatar asked May 28 '19 19:05

Lambda1010


1 Answers

HistoryIterator implements the AsyncIterator interface. You can use the AsyncIterator.flatten method to consume the contents of the Iterator into a list:

messages = await channel.history(limit=200).flatten()
like image 123
Patrick Haugh Avatar answered Sep 27 '22 00:09

Patrick Haugh