我将如何编写一个嵌入代码,从我有 URL 的一组图像中提供一个随机图像? (不和谐.py)

Posted

技术标签:

【中文标题】我将如何编写一个嵌入代码,从我有 URL 的一组图像中提供一个随机图像? (不和谐.py)【英文标题】:How would I code an embed that gives a random image from a set of images I have the URLs of? (Discord.py) 【发布时间】:2021-02-28 17:53:48 【问题描述】:

这就是它现在的样子。它不起作用,因为当我在 (.testyi) 中键入命令时,我的机器人只是想出了一个薄的空白嵌入。

async def testyi(ctx):
    items = [
    discord.Embed(image = "thaturlwhatever.jpeg", url = "thaturlwhatever.jpg")
    discord.Embed(image = "thatotherurlwhatever.jpeg", url = "thatotherurlwhatever.jpg")]
    randomitem = random.choice(items)
    await ctx.send(embed=randomitem)

【问题讨论】:

如果你能准确地解释什么“不起作用”会很有用。 好的,现在指定了。 【参考方案1】:

你可以这样做:

@client.command() 
async def hell(ctx):
    items = ['url_0','url_1','url_2']
    
    embed = discord.Embed()
    embed.set_image(url=random.choice(items))
    await ctx.send(embed=embed)

将所有网址放入items 列表中,然后使用random.choice(items) 获取随机网址!embed.set_image 函数没有名为 name 的参数,因此我们不能在此方法中使用名称,所以我只是跳过了名称! 而且你不能直接添加这样的图像discord.Embed(image='url')你需要使用embed.set_image(url='url')[set_image: document]

【讨论】:

以上是关于我将如何编写一个嵌入代码,从我有 URL 的一组图像中提供一个随机图像? (不和谐.py)的主要内容,如果未能解决你的问题,请参考以下文章

计算图像嵌入与一组图像嵌入的距离

尝试从我的 JSON 文件访问一组图像到我的 JS 代码

如何在 Android 上从我的应用程序启动 URL?

我将如何着手修复嵌入命令中的意外标记/添加 <用户提及> 功能?

如何以编程方式在 Fabric.js 呈现的一组图像中选择一个图像

如何将一组图像上传到 Firebase 存储?