简体   繁体   English

在 Discord.py 的嵌入中发送 gif

[英]Sending gifs inside a Embed in Discord.py

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

This is my code.这是我的代码。 In if not ctx.channel.is_nsfw(): part i want to send a gif. if not ctx.channel.is_nsfw():部分我想发送一个 gif。 I know that by default you can't send a gif I am pretty sure there is a way for it.我知道默认情况下你不能发送 gif 我很确定有办法。 If there is I don't know and would be happy to learn from you guys!如果有我不知道,很乐意向你们学习!

When setting an image in an embed, it needs to be the direct link to the image ( https://example.com/path/to/image.png ) - you'll know this if your url ends in a filetype ( .png , .bmp , .jpg , .gif etc.).在嵌入中设置图像时,它必须是图像的直接链接( https://example.com/path/to/image.png ) - 如果您的 url 以文件类型( .png.bmp.jpg.gif等)。

To get this, you want to right click your image/gif, and Copy Image Location :为此,您需要右键单击您的图像/gif,然后Copy Image Location

在此处输入图像描述

So in your case, you'd want:所以在你的情况下,你会想要:

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

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM