在嵌入Discord.py中发送GIF

2024-09-28 22:38:57 发布

您现在位置:Python中文网/ 问答频道 /正文

@client.command(aliases=["rule34"])
async def nsfw(ctx):
        if not ctx.channel.is_nsfw():
            embed = discord.Embed(
                title=":x: Channel Is Not NSFW",
                color=discord.Colour.purple()
            )
            embed.set_image(url="https://giphy.com/gifs/W5C9c8nqoaDJWh34i6")
        else:
            async with ctx.channel.typing():
                memes_submissions = reddit.subreddit("rule34").hot()
                post_to_pick = random.randint(1, 10)
                for i in range(0, post_to_pick):
                    submission = memes_submissions.__next__()
                embed = discord.Embed(
                    title=submission.title,
                     color=discord.Colour.purple()
                )
                embed.set_image(url=submission.url)
                embed.add_field(name="Author", value="u/" + submission.author.name, )
                embed.add_field(name="View Online", value=f"[Link]({submission.url})", )
                embed.add_field(name="Subreddit", value="r/rule34", )
        await ctx.send(embed=embed)

这是我的密码。在if not ctx.channel.is_nsfw():部分,我想发送一个gif。我知道默认情况下你不能发送gif,我很确定有办法。如果有,我不知道,很高兴向你们学习


Tags: nameaddurlfieldsubmissionasynciftitle
1条回答
网友
1楼 · 发布于 2024-09-28 22:38:57

在嵌入中设置图像时,它需要直接链接到图像(https://example.com/path/to/image.png)-如果url以文件类型(.png.bmp.jpg.gif等)结尾,您就会知道这一点

要获取此信息,请右键单击图像/gif,然后Copy Image Location

enter image description here

因此,在您的情况下,您希望:

embed.set_image(url="https://media0.giphy.com/media/W5C9c8nqoaDJWh34i6/giphy.gif")

参考资料:

相关问题 更多 >