discord-api-docs icon indicating copy to clipboard operation
discord-api-docs copied to clipboard

Image embeds not always showing

Open LordTylus opened this issue 4 months ago • 22 comments

Description

Hello there,

I stumbled upon a problem with Message Embeds in the discord API.

Using the Java Discord API I am creating a message Embed containing a title, description and an image. However, on about 50% of the cases the image does not show up in the embed.

Steps to Reproduce

Using the Java Discord API I am creating a message embed as follows:

        EmbedBuilder embedBuilder = new EmbedBuilder();

        embedBuilder.setImage(post.getImageUrl());
        embedBuilder.setDescription(sb);
        embedBuilder.setAuthor(blogUrl, post.getUrl());
        embedBuilder.setTitle(title, post.getUrl());

        return embedBuilder.build();

And then I post it using

    Optional<TextChannel> textChannel = getTextChannelWithName(guild, channelName);

    if (textChannel.isEmpty())
        return;
                
    textChannel.get().sendMessageEmbeds(messageEmbed.get()).queue();

The code is a little simplified. But its essentially what I do.

When the message embed is posted, sometimes the image does not appear. I used the API to look at the message itself and see that there are some differences, which are described ablow.

Expected Behavior

When creating an image embed with an Image URL I expect it to display correctly within discord itself.

The Message Embed should look something like this: image

Current Behavior

Right now in about 50 % of the cases the Image Embed looks like this:

image

There Width and Height of the Image are not properly set.

Since I am just passing an Image URL and cannot pass things like the width and height myself, I assume there must be a bug somewhere in discord. This was confirmed on the JDA discord server.

Screenshots/Videos

The following image shows two messages. One one which the URL worked, and one on which it did not.

image

Client and System Information

Using Java Discord API Version 5.0.0 Beta 20 to connect to Discord API

I reproduced the Issue in the following versions on Windows 11 and Discord Client image

It was also seen on Android and probably any other platform, since the width and height of the image appear to be incorrectly returned by the API

LordTylus avatar Mar 04 '24 01:03 LordTylus

Additional information:

Sometimes just posting an Image Link also doesnt seem to be rendered: image

Posted it twice, the first one was not rendered, all subsequent ones were without problem.

LordTylus avatar Mar 04 '24 01:03 LordTylus

Additional Information:

Uploading the Image and referencing it in the Embed works fine every time. So the problem seems to be related to external links. I really don't want to upload a bunch of files to discord when it is not needed, since everything is already online on the respective website.

LordTylus avatar Mar 04 '24 01:03 LordTylus

@LordTylus are you able to reproduce this with all external hosted images or just ones hosted on www.twinsdragonscomic.com?

sklein12 avatar Mar 04 '24 22:03 sklein12

@sklein12 certainly not on all.

I can consistently reproduce it with twindragonscomic.com and savestatecomic.com

Both seem to run on WordPress. The owners are independent and they have independent servers as well.

I tested it with image links that point to Tumblr's cdn and those work just fine. And image links pointing to DeviantArt also seem to work without issue.

These WordPress pages aren't the quickest to respond. And if they work it takes a few good seconds till the image appears in the embed. While the links to Tumblr or DeviantArt appear near instantly.

Could there be a timeout involved?

I have seen images. Not loading occasionally in the past. Maybe once a month. So I never gsve it mich thought. That it is this bad only happens for about a week.

When I upload the images as file attachments to discord and reference the attachment in the embed it works fine too. So I am starting to believe that it might be related to WordPress. But sadly I don't have any way of analyzing what's happening.

LordTylus avatar Mar 05 '24 00:03 LordTylus

A quick scan of the code indicates that we'd timeout after 5 seconds. In my playing around right now, the images load pretty instantly and are unfurling very consistently. Its possible that when this site is under load it fails to respond within 5 seconds and we give up

yonilerner avatar Mar 05 '24 00:03 yonilerner

This is rather odd.

When it works I never had to wait 5 seconds. It took a like maybe 1 to 2 seconds. When I download the picture first via OkHttpClient and upload it, its also always like 1 second. (Gut feeling I never measured it)

Opening an image in browser without cache also seems to be rather quick. I can run additional tests tonight, where I take more exact time measurements. And not just gut feeling.

Plan is I download a picture via OkHttpClient 20 times to see what the min avg and max load times are. And I Link to it via discord embed and see how many of those fail. Alternatively I load ans post 20 different pictures.

I mean of course there are other things that could ve at play here. Latency potentially depending on where the servers are physically located and where its being connected from.

LordTylus avatar Mar 05 '24 07:03 LordTylus

Hello there again,

sorry for the long wait. But I have conducted a few more tests: First I attempted to send the same picture 20 Times with little to no delay in between. The result was, that out of the 20 times. 5 were successful 15 failed.

image image

Running the test again resulted in 20 pictures not being displayed. Probably some spam detection going on? Not sure... image

Then I added some delay of 2 seconds between sending an embed with the same picture. Those were 20 successful ones. image

And then I grabbed 20 random Image URLs from my archive measured the times and output:

        try {

            List<String> urls = List.of(
                    "https://www.twindragonscomic.com/wp-content/uploads/2019/11/Twin_Dragons_221.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2019/06/Twin_Dragons_201.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2022/11/Twin_Dragons_368.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2016/04/Twin_Dragons_035.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2023/10/Twin_Dragons_419.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2020/09/Twin_Dragons_267.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2016/04/Twin_Dragons_036.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2020/04/Twin_Dragons_245.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2017/09/Twin_Dragons_108.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2022/09/Twin_Dragons_362.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2018/12/Twin_Dragons_174.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2020/06/Twin_Dragons_253.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2018/01/Twin_Dragons_123.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2024/03/Twin_Dragons_437.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2016/01/Twin_Dragons_022.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2022/09/Twin_Dragons_359.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2017/12/Twin_Dragons_121.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2023/03/Twin_Dragons_388.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2018/09/Twin_Dragons_160.png",
                    "https://www.twindragonscomic.com/wp-content/uploads/2016/10/Twin_Dragons_061.png"
            );

            OkHttpClient okHttpClient = new OkHttpClient();

            int i = 0;

            for (String url : urls) {

                Thread.sleep(2000);

                long start = System.currentTimeMillis();

                Request request = new Builder().url(url).build();

                try (Response response = okHttpClient.newCall(request).execute()) {

                    ResponseBody body = response.body();
                    if (body != null)
                        log.info("{} - loaded {} bytes in {} ms", i, body.bytes().length, System.currentTimeMillis() - start);
                }

                TextChannel textChannelById = guild.getTextChannelById(1082027410683338852L);

                MessageEmbed embed = new EmbedBuilder()
                        .setTitle(i + " Title")
                        .setAuthor("Me")
                        .setImage(url)
                        .setDescription("This is a Test")
                        .build();

                textChannelById.sendMessageEmbeds(embed).queue();

                i++;
            }

        } catch (IOException e) {
            log.error("Error", e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

The following Result was output:

17:29:50,522 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 0 - loaded 617369 bytes in 1364 ms
17:29:53,236 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 1 - loaded 670099 bytes in 702 ms
17:29:55,944 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 2 - loaded 698810 bytes in 705 ms
17:29:58,635 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 3 - loaded 585526 bytes in 688 ms
17:30:01,348 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 4 - loaded 662221 bytes in 701 ms
17:30:04,042 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 5 - loaded 608909 bytes in 692 ms
17:30:06,722 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 6 - loaded 499930 bytes in 676 ms
17:30:09,408 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 7 - loaded 505202 bytes in 683 ms
17:30:12,101 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 8 - loaded 549066 bytes in 687 ms
17:30:14,820 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 9 - loaded 684347 bytes in 707 ms
17:30:17,521 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 10 - loaded 639092 bytes in 700 ms
17:30:20,204 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 11 - loaded 527214 bytes in 682 ms
17:30:23,115 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 12 - loaded 550961 bytes in 907 ms
17:30:25,826 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 13 - loaded 644565 bytes in 698 ms
17:30:28,500 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 14 - loaded 475130 bytes in 673 ms
17:30:31,192 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 15 - loaded 576589 bytes in 690 ms
17:30:33,891 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 16 - loaded 617201 bytes in 695 ms
17:30:36,584 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 17 - loaded 560529 bytes in 691 ms
17:30:39,278 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 18 - loaded 598631 bytes in 692 ms
17:30:41,961 [INFO ] [JDA MainWS-ReadThread] [DebugModule] 19 - loaded 498583 bytes in 678 ms

As you can see every image was loaded by my OkHttpClient within ~700ms

However there were a few images that were not loaded: image (ignore the 0 Title... I forgot to advance i in my loop -.-

But I could see that the following URLs were not displayed correctly.

                "https://www.twindragonscomic.com/wp-content/uploads/2022/11/Twin_Dragons_368.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2020/09/Twin_Dragons_267.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2016/04/Twin_Dragons_036.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2018/12/Twin_Dragons_174.png",

I then ran the test again.

This time, some of the previous images were displayed correctly. Others, however, were no longer: image

                "https://www.twindragonscomic.com/wp-content/uploads/2022/11/Twin_Dragons_368.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2016/04/Twin_Dragons_036.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2018/12/Twin_Dragons_174.png",

these failed to load.

I kind of dont believe its a timeout issue, since the server seems to respond to my requests just fine in an acceptable amount of time. Loading the preview however seems to randomly not work.

I hope this helps narrowing the issue down.

LordTylus avatar Mar 05 '24 16:03 LordTylus

This is incredibly helpful, thank you. We will continue to investigate on our side

yonilerner avatar Mar 05 '24 20:03 yonilerner

This time, some of the previous images were displayed correctly. Others, however, were no longer:

It sounds like you're saying here that some that previously loaded were no longer loading, but the list of images that didn't load

                "https://www.twindragonscomic.com/wp-content/uploads/2022/11/Twin_Dragons_368.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2016/04/Twin_Dragons_036.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2018/12/Twin_Dragons_174.png",

seems to be a subset of the first set of images that didn't load.

Just want to confirm that there are no images that loaded in the first test of 20 different images that didn't in the 2nd test

yonilerner avatar Mar 05 '24 20:03 yonilerner

I double checked it just now. You are right I thought it loaded one less, but apparently it didn't.

However, I just ran this test again. And you are right, it could still load all previous images and 1 extra. So now only

                "https://www.twindragonscomic.com/wp-content/uploads/2016/04/Twin_Dragons_036.png",
                "https://www.twindragonscomic.com/wp-content/uploads/2018/12/Twin_Dragons_174.png",

it couldn't load.

I guess Ill have to use a different random set next, if there actually is some caching involved I could imagine after testing a few more times it will have all of them.

LordTylus avatar Mar 05 '24 20:03 LordTylus

Ya so we cache successes for a day and we cache failures for 5 minutes. So that explains both why you never see things that used to succeed start to fail, and why testing a single image 20 times with no delay after it failed once failed all 20 of them.

As for why its failing to begin with.. unclear still. Our tracing shows that we are indeed timing out when trying to fetch the images, but its not clear why yet.

yonilerner avatar Mar 05 '24 20:03 yonilerner

I believe I'm experiencing the same or similar bug, though I've found something interesting - in my case most images do load properly for a split second, but then have their width and height set to 0 by a Message Update event.

https://github.com/discord/discord-api-docs/assets/9750071/ebce24e2-b856-49e3-9a59-1240dc796f22

The gateway events

image

Similarly to the OP, all further attempts to embed the particular urls work fine, only the initial attempt fails.

I'm serving the images from my own express server, and I'm pretty certain that it isn't timing out. I've added some logging to the incoming requests when this issue occurs and got the following output:

2024-03-15T00:33:07: 1 Request from ip: 35.237.4.214 UA: Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com) to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:07: Fulfilled request 1 after 0.06 seconds
2024-03-15T00:33:07: 2 Request from ip: 34.74.48.54 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:07: Fulfilled request 2 after 0 seconds
2024-03-15T00:33:07: 3 Request from ip: 34.23.59.147 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:07: Fulfilled request 3 after 0 seconds
2024-03-15T00:33:08: 4 Request from ip: 34.74.48.54 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:08: Fulfilled request 4 after 0.02 seconds
2024-03-15T00:33:08: 5 Request from ip: 35.237.99.52 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:08: Fulfilled request 5 after 0 seconds
2024-03-15T00:33:08: 6 Request from ip: 35.237.129.219 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:08: Fulfilled request 6 after 0 seconds
2024-03-15T00:33:08: 7 Request from ip: 34.23.59.147 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:08: Fulfilled request 7 after 0 seconds
2024-03-15T00:33:09: 8 Request from ip: 34.74.42.166 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:09: Fulfilled request 8 after 0 seconds
2024-03-15T00:33:10: 9 Request from ip: 34.23.59.147 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:10: Fulfilled request 9 after 0.02 seconds
2024-03-15T00:33:12: 10 Request from ip: 34.23.59.147 UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0 to path: /37feabb9c24b1b33ad640fc9fdcfc2d8.png
2024-03-15T00:33:12: Fulfilled request 10 after 0 seconds

(I did the testing in my own private guild so there was only one client attempting to load the images).

aamiaa avatar Mar 15 '24 00:03 aamiaa

I wanted to chime in and say I'm having the same issue with images not appearing in embeds, albeit with discord.js, and I'm serving them from my AWS S3 bucket. Historically they don't appear on occasion and attempting the same request a second time works, but it's been pretty reliably failing no matter the number of retry attempts in the past 24 hours. Pasting the image URL by itself causes the image to appear just fine

cjm333 avatar Mar 24 '24 02:03 cjm333

I am having the same issue even with images served with cloudflare like: https://s4.anilist.co/file/anilistcdn/character/large/b138850-eqwZ11Q6sLrl.png

image Screenshot from 2024-04-17 13-37-55

I noticed that discord sends ~5 requests for the same image with no delay between requests, this started happening around the time images started to break about ~2 weeks ago.

first request from "user-agent": "Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)", and the others from "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0",

ker0olos avatar Apr 17 '24 16:04 ker0olos

Thanks for continuing to provide info everyone. We had to take a break from investigating this but it is still on our radar, and we should resume investigation shortly

yonilerner avatar Apr 18 '24 18:04 yonilerner

Hi @ker0olos @cjm333 and @LordTylus . Joining this thread to help solve the issue. I've been performing some tests since last Friday based on the information provided here, using same hosts and/or images, but I couldn't reproduce the issue on my side.

We've made some changes to media last week, so I want to confirm with you first if the issue is still occurring as of today/last Friday?

If it is, I need to be able to either reproduce the issue or at least get a "fresh" trace from one of your failed requests so that I can troubleshoot.

Can you provide the following details:

  • API type: webhook/bot/direct API
  • Framework used, if any?
  • Image URL used? From a "fresh" request failure from today ideally else from the past 2-3 days max
  • The time the request was performed at, approximately
  • Does the image appears if you change channel, after a few minutes or never?

Thanks!

remiolivier-discord avatar Apr 22 '24 18:04 remiolivier-discord

Hello @remiolivier-discord,

thank you for the update. I just tried out my reproducer I posted above again. And all 20 of 20 images have been posted correctly.

I will test out different URLs later, when I have a little more time. But so far it seems to be working fine.

LordTylus avatar Apr 22 '24 18:04 LordTylus

Hello @remiolivier-discord,

I'm facing a similar issue when using a bot to create embeds on a server (the thumbnail image, nor image fields, have their images loading). The URLs also don't load when posted to a channel standalone.

The details you'd requested -

  • API type: bot
  • Framework used: discord.py
  • Image URL used?
https://wavu.wiki/t/Special:Redirect/file/Reina-1,1,2.jpg
https://wavu.wiki/w/images/4/49/Reina-1%2C1%2C2.jpg
https://wavu.wiki/android-chrome-192x192.png
https://wavu.wiki/w/images/c/cb/AsukaT8.png
  • The time the request was performed at, approximately: 2024/05/02 16:00:00 EST (approx.)
  • Does the image appears if you change channel, after a few minutes or never?: Never reappears even if channel is changed

This doesn't happen with all images. For example, https://cdn.discordapp.com/embed/avatars/0.png works fine (image preview when link is posted in a channel, or when link is used as an embed).

I'd be happy to provide whatever additional info you would find helpful in resolving this issue.

AbhijeetKrishnan avatar May 02 '24 20:05 AbhijeetKrishnan

https://wavu.wiki/w/images/4/49/Reina-1%2C1%2C2.jpg

Hi! This looks like a different issue, but for this one, wavu.wiki is blocking our discord service to retrieve images and returns a 403, therefore we can't display the image

remiolivier-discord avatar May 09 '24 15:05 remiolivier-discord

Hello again @remiolivier-discord,

I am terribly sorry for the long delay, but today I finally got to performing a thorough test. I have used my bot to post 100 different embeds and all 100 worked flawlessly.

So, I will now change my bots back to embed URLs instead of uploading them to discord whenever needed.

I don't know about all the others that have posted here, but as far as I am concerned, my Issue has been resolved.

LordTylus avatar May 09 '24 15:05 LordTylus

Hello again @remiolivier-discord,

I am terribly sorry for the long delay, but today I finally got to performing a thorough test. I have used my bot to post 100 different embeds and all 100 worked flawlessly.

So, I will now change my bots back to embed URLs instead of uploading them to discord whenever needed.

I don't know about all the others that have posted here, but as far as I am concerned, my Issue has been resolved.

Great news! Happy it is working normally!

remiolivier-discord avatar May 09 '24 15:05 remiolivier-discord