Carter Michaelis
Carter Michaelis

Reputation: 275

Programming a Discord bot in Python- Why is it unable to set embed images?

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)

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.

Upvotes: 1

Views: 232

Answers (1)

Junelilly
Junelilly

Reputation: 394

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.

For gfycat, The alternative link format https://thumbs.gfycat.com/ElatedEvergreenGoose-size_restricted.gif can be used

Upvotes: 2

Related Questions