我该如何编码一个嵌入,从我拥有URL的一组图像中随机生成图像?(Discord.py)



下面是它现在的样子。但是它不起作用,因为当我在(.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)

您可以这样做:

@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)

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

最新更新