#How do I get the first message in the channel?
1 messages · Page 1 of 1 (latest)
use channel.history with limit=1 and oldest_first=True
Ok I got <discord.iterators.HistoryIterator object at 0x0000024E7701C490>
see how to use it at https://docs.pycord.dev/en/master/api.html#discord.TextChannel.history
How can I get a message out of this?
literally that link
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>
you have to await it
alsopy channel = interaction.client.get_channel(interaction.user.voice.channel.id)why...
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
yeah but
interaction.user.voice.channel.id
you can just use interaction.user.voice.channel instead of get_channel
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'
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
?? what's your code now
@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)
^
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>>]
I want to get the first message from the voice channel and get the text from the embed message
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
So far, the only problem is getting the message id
I don't understand how to get it from there
mess is a list of message objects
or in your case, a list of the first message in that channel as a list of discord.Message object
That is, just attribute to mess.content?
mess[0].content
Done with your help thread?
Please close your own help thread using </close:882631512829329448> (
/close) with @thorn steeple.