Issue
I have code that (wants) prints out message history, however I get a barely useful slur of info, IDs and more.
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<Member id=x name='Cheesebot' discriminator='1916' bot=True nick=None guild=<Guild id=x name='NoLife Minecraft' shard_id=None chunked=False member_count=18>> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<User id=x name='' discriminator='3912' bot=False> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<Member id=x name='Cheesebot' discriminator='1916' bot=True nick=None guild=<Guild id=x name='NoLife Minecraft' shard_id=None chunked=False member_count=18>> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<User id=x name='' discriminator='3912' bot=False> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<User id=x name='' discriminator='3912' bot=False> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<User id=x name='' discriminator='3912' bot=False> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<Member id=x name='Cheesebot' discriminator='1916' bot=True nick=None guild=<Guild id=x name='NoLife Minecraft' shard_id=None chunked=False member_count=18>> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<Member id=x name='Cheesebot' discriminator='1916' bot=True nick=None guild=<Guild id=x name='NoLife Minecraft' shard_id=None chunked=False member_count=18>> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<User id=x name='' discriminator='3912' bot=False> flags=<MessageFlags value=0>>
<Message id=x channel=<TextChannel id=x name='general' position=5 nsfw=False news=False category_id=x> type=<MessageType.default: 0> author=<Member id=x name='Cheesebot' discriminator='1916' bot=True nick=None guild=<Guild id=x name='NoLife Minecraft' shard_id=None chunked=False member_count=18>> flags=<MessageFlags value=0>>
The code I have right now is this:
async def messagesl(sendc):
messages = await sendc.history(limit=10).flatten()
return messages
What I need is a way to get the message contents, and other info like user, etc.
sensitive info is an x (or for names, nothing.)
Solution
Simply loop through the messages and access the attributes you need
messages = await sendc.history(limit=10).flatten()
contents = []
for message in messages:
contents.append(message.content)
If you want a one-liner
contents = [message.content for message in messages]
Answered By - Łukasz Kwieciński
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.