問題描述
我有一個(gè) meme 命令,它從 subreddit 獲取 URL,然后將其設(shè)置為嵌入圖像.這是我的代碼:
I have a meme command that gets a URL from a subreddit and then sets it as an embed image. Here's my code:
memes = reddit.subreddit("memes")
memes_subs = []
memes_hot = memes.hot(limit = 50)
for submission in memes_hot:
memes_subs.append(submission)
@client.command()
async def meme(ctx):
random_sub = random.choice(memes_subs)
name = random_sub.title
url = random_sub.url
em = discord.Embed(title = name, color = 0xfdcb58)
em.set_footer(text = f"Requested by {ctx.message.author} | From r/memes")
em.set_image(url = url)
await ctx.send(embed = em)
有時(shí)嵌入沒有圖像,或者圖像根本無法加載.我不確定為什么會(huì)發(fā)生這種情況,因此任何見解都將不勝感激.
Sometimes the embed does not have an image, or the image simply won't load. I am unsure why this happens, so any insight would be greatly appreciated.
推薦答案
一些 Imgur URL 以 gifv 結(jié)尾,因?yàn)樗鼈兪蔷W(wǎng)頁(yè),而不是直接鏈接.要獲取原始 GIF,您可以將鏈接更改為以下格式:http://i.imgur.com/12345.jpg
請(qǐng)注意 .jpg,而不是 .gif.不過,這會(huì)給你一個(gè)原始的 GIF 文件.
Some Imgur URLs end in gifv because they are web pages, not direct links. To get the original GIF, you can change the link into this format: http://i.imgur.com/12345.jpg
Note the .jpg, not a .gif. This will give you a raw GIF file though.
對(duì)于gfycat,可以使用替代鏈接格式https://thumbs.gfycat.com/ElatedEvergreenGoose-size_restricted.gif
For gfycat, The alternative link format https://thumbs.gfycat.com/ElatedEvergreenGoose-size_restricted.gif
can be used
這篇關(guān)于用 Python 編寫 Discord 機(jī)器人 - 為什么它無法設(shè)置嵌入圖像?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!