添加不和谐缩略图的问题

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

当链接是网站的直接链接时,无法将不和谐图像嵌入到缩略图字段中。

例如- 不起作用: https://www.sevenstore.com/images/products/medium/4091615.jpg

有效: https://i8.amplience.net/i/jpl/hp_598600_a?qlt=100&w=750&h=750&bg=rgb%28232%2C230%2C231%29&v=1&fmt=auto

我们首先将这些写入数据库,当点击两者时它们工作正常。写入数据库或获取图像链接没有问题。唯一的问题是设法让该图像在不和谐中设置为缩略图。

def BotStart():
    if (EnableBot == 1):
        webhook = DiscordWebhook(url=DISCORD_WEBHOOK_URL)
        embed = DiscordEmbed(
            title=Name,
            url=Link,
            color=0xb229ce,
            description="**Now in stock!**",
            timestamp=now
        )
        embed.add_embed_field(
            name="",
            value="",
            inline=False
        )
        embed.set_thumbnail(
            url=Image
        )
        embed.add_embed_field(
            name="Price:",
            value=str(Price),
            inline=True
        )
        embed.add_embed_field(
            name=chr(173),
            value="Post in success and tag our socials",
            inline=False
        )
        embed.add_embed_field(
            name="",
            value="[Twitter](https://twitter.com/N1Pings) | [Instragram](https://www.instagram.com/nice1pings/)",
            inline=False
        )
        embed.set_image(
            url=Banner
        )
        embed.set_footer(
            text="Nice1 Pings",
            icon_url=BotLogo
        )
        webhook.add_embed(embed)
        response = webhook.execute() 

我们不想下载图像。

还测试了尝试添加图像但也不起作用。

TIA

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

你可以试试这个

@bot.command("a")
async def a(ctx: commands.Context):  # Just a sample command
    img_url = "https://www.sevenstore.com/images/products/medium/4091615.jpg"

    embed = discord.Embed(title="Sample Embed")

    async with aiohttp.ClientSession() as session:
        async with session.get(img_url) as resp:
            img = await resp.read()
            with io.BytesIO(img) as image:
                file = discord.File(image, filename="thumbnail.png")

    embed.set_thumbnail(url="attachment://thumbnail.png")

    await ctx.send(embed=embed, file=file)

它仍然会下载图像,但不会将其存储在内存中以外的任何地方

确保导入

aiohttp

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