簡體   English   中英

如何從discord.py的文本通道中獲取所有消息的數組?

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

我有頻道對象,我已經嘗試過

mess = channel.history(limit=200)

但是mess是一個HistoryIterator對象,並且在mess.messages對象中不包含任何消息(大小= 0)。 通道中有消息,因此不應說大小為0。

我也嘗試過:

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

但是PyCharm告訴我, client沒有logs_from函數。

有沒有一種簡單的方法可以從數組中的文本通道獲取所有消息?

HistoryIterator實現AsyncIterator接口。 您可以使用AsyncIterator.flatten方法將Iterator的內容消耗到一個列表中:

messages = await channel.history(limit=200).flatten()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM