Search code examples
pythondiscord.jsdiscord.pybotsscreen-scraping

Is there a way to manipulate the order of execution of arguments in a Discord.py async function?


First off, I apologize if I am using wrong terminologies on this question. Hopefully, I can come through with the details.

I am trying to send files(local images) and embed using the command await channel.send(files=files, embed=embedvar) and the output normally is like this: current_output The images are above the embed.

What I would like to know is if there is a way to have the images below the embed? Basically, to run the embed argument first then the files argument using a single await channel.send()

I saw this post regarding .send() being a promise and using .then() to separate the embed then files but I have no way to check and implement this without learning JavaScript. I did try to implement it using JS to PY packages but I think I have to mess with the transfer of data using stuff like JSON. I am hoping as well for direction if this is possible to implement and try in the Python language by itself. Discord.js send file after embed

Snippet of the code:


        embedvar = discord.Embed(title=f'🔗 {name}', description=text, url=link)
        embedvar.set_author(name=user, icon_url=img)
        embedvar.add_field(name="", value="", inline=True)
        embedvar.set_footer(text=f'Posted on: Requested by:')

        files = []
        for filename in os.listdir(path):
            file_path = os.path.join(path, filename)
            files.append(discord.File(file_path, filename))

        channel = bot.get_channel(*channel)
        await channel.send(files=files, embed=embedvar)

Thank you.


Solution

  • The Javascript code in the snippet is sending 2 messages. You can do the same in Python simply like this:

    await channel.send(embed=embedvar)
    await channel.send(files=files)
    

    As far as I know, it's not possible to choose the order of images/embed in a single message, so you have to send 2 separate messages.