#How do I get the first message in the channel?

1 messages · Page 1 of 1 (latest)

coral moth
#

How do I get the first message in the channel?

fresh sandal
coral moth
#

Ok I got <discord.iterators.HistoryIterator object at 0x0000024E7701C490>

fresh sandal
coral moth
#

How can I get a message out of this?

vapid gulch
coral moth
#

Unfortunately, what is written there did not help me.

#
    @discord.ui.button(label="", custom_id="button-6", row=1, style=discord.ButtonStyle.secondary, emoji=":view:") 
    async def button_callback6(self, button, interaction):
        channel = interaction.client.get_channel(interaction.user.voice.channel.id)
        mess = channel.history(limit=1, oldest_first=True).flatten()
        print(mess)

When the button is activated, it writes this
<coroutine object _AsyncIterator.flatten at 0x000001C2525636F0>

fresh sandal
#

you have to await it

#

alsopy channel = interaction.client.get_channel(interaction.user.voice.channel.id)why...

coral moth
#

Because I need to take the first message from the voice channel

#

The bottom line is that the bot creates a channel, moves the participant there and writes his id to the chat and I need to get this id

fresh sandal
#

yeah but

#

interaction.user.voice.channel.id

#

you can just use interaction.user.voice.channel instead of get_channel

coral moth
#

I can not

#
Ignoring exception in view <PrivateVoice timeout=None children=8> for item <Button style=<ButtonStyle.secondary: 2> url=None disabled=False label='' emoji=<PartialEmoji animated=False name='view' id= 1015340521729839154> row=1>:
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 396, in _scheduled_task
    await item.callback(interaction)
  File "C:\Users\User\Documents\Testings\CMSelfBot\module\privatechannel.py", line 29, in button_callback6
    mess = channel.history(limit=1, oldest_first=True).flatten()
AttributeError: 'int' object has no attribute 'history'
fresh sandal
#

remove .id

#

and again, you need to await channel.history

coral moth
#

Now another error

#
<coroutine object _AsyncIterator.flatten at 0x00000293941E4040>
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py:396: RuntimeWarning: coroutine '_AsyncIterator.flatten' was never awaited
  await item.callback(interaction)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
fresh sandal
#

?? what's your code now

coral moth
#
@discord.ui.button(label="", custom_id="button-6", row=1, style=discord.ButtonStyle.secondary, emoji=":view:")
async def button_callback6(self, button, interaction):
channel = interaction.user.voice.channel
mess = channel.history(limit=1, oldest_first=True).flatten()
print(mess)
coral moth
#

give me a sec

#

Thanks

#

Now it writes clear text

#
[<Message id=1016158551154102333 channel=<VoiceChannel id=1016158545017843804 name='BazZziliuS Channel' rtc_region=None position=8 bitrate=64000 video_quality_mode=<VideoQualityMode.auto: 1> user_9=2 category_id>defage.Type.06<Message28 type2 : 0> author=<Member id=1012769035387142185 name='CenturyBOT' discriminator='1091' bot=True nick=None guild=<Guild id=350817461328805888 name='[DEV] BazZziliuS' shard_id=0 chunked=True member_count=11 >> flags=<MessageFlags value=0>>]
bold sierra
#

congratz

#

so what do you want it to do

coral moth
bold sierra
#

In order to get the embed object from a message, you can use message.embeds. This will return you a list of embeds that the message has.

#

so how i would do it personlly is

#

instead of flatten cuz idk what that is lol for loop through it than get message.embeds.description

#

or somthing like that

coral moth
#

So far, the only problem is getting the message id

coral moth
vapid gulch
#

or in your case, a list of the first message in that channel as a list of discord.Message object

coral moth
#

That is, just attribute to mess.content?

vapid gulch
coral moth
#

Hooray! You helped me get what I wanted

#

Thanks

vapid gulch
#

np

#

?tag solved

fallen saffronBOT
#

Done with your help thread?

Please close your own help thread using </close:882631512829329448> (/close) with @thorn steeple.