有没有办法操纵 Discord.py 异步函数中参数的执行顺序?

问题描述 投票:0回答:1

首先,如果我在这个问题上使用了错误的术语,我深表歉意。希望我能提供详细信息。

我尝试使用命令

files
发送
embed
(本地图像)和
await channel.send(files=files, embed=embedvar)
,输出通常如下所示: 当前输出 图像位于嵌入上方。

我想知道是否有办法将图像嵌入到下面?基本上,首先运行

embed
参数,然后使用单个
files
 运行 
await channel.send()

参数

我看到这篇文章关于

.send()
是一个承诺,并使用
.then()
来分隔
embed
然后
files
但我无法在不学习 JavaScript 的情况下检查和实现这一点。我确实尝试使用 JS 到 PY 包来实现它,但我认为我必须使用 JSON 之类的东西来处理数据传输。如果可以用 Python 语言本身实现和尝试,我也希望得到指导。 Discord.js 嵌入后发送文件

代码片段:


        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)

谢谢你。

python discord.js discord.py bots screen-scraping
1个回答
0
投票

代码片段中的 Javascript 代码正在发送 2 条消息。您可以像这样在 Python 中执行相同的操作:

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

据我所知,无法在一条消息中选择图像/嵌入的顺序,因此您必须发送 2 条单独的消息。

© www.soinside.com 2019 - 2024. All rights reserved.