What methods exist to copy a gif to the clipboard and post it into other applications?

I want to (programmatically) copy a gif to the clipboard such that I can paste it into modern chats like those of MS Teams or Discord.

There seem to be some “magic” happening in the backgroud when you do a "right-click => copy" that I haven’t yet figured out.

For example, this gif from reddit (also those of tenor) can be copied to both Teams and Discord.
This from giphy works on Teams, but not on Discord. On Discord it’s interpreted as a png object.
If I open a local gif file in the browser and copy it to the clipboard it’s also interpreted as a png by Discord while nothing happens in Teams.

This awesome stackoverflow comment explains how to use different APIs for clipboard access – with ClipboardItem still not being available in Firefox, and document.execCommand('copy') being deprecated.

However, with gifs there seems to be something extra needed to make it work with gifs. Does anyone know what?