English 中文(简体)
机器人不和问题。 j 未发送全球投资论坛成果
原标题:The problem of a bot discord.js not sending a GIF result

我已经制定了一个简单的方案,利用不和,我想把仍然的形象与含有im化框架的形象结合起来,那么,机器人将传播一个形象中的形象和仍然形象的背景。

const Discord = require( discord.js );
const sharp = require( sharp );
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

client.on( messageCreate , async message => {
    if (message.content ===  !merge ) {
        const background = await sharp( logo.png ).resize(288, 288);
        const overlay = await sharp( banana.gif ).resize(288, 288);

        const result = await background.composite([{ input: await overlay.toBuffer(), gravity:  center  }]).toBuffer();

        message.channel.send({ files: [result] });
    }
});

client.login( your-token );

But the result was not successful, it sends a static image without the animated frames in GIF format.
I tried to search for a package, but did not find anything.

我们希望有人能够帮助我们这样做,感谢你。

问题回答

In order to create an animated image you must tell sharp to animate the result of the composite.

According to the documentation the default behavior of composite is to have a default value of animated = false. So what you want to do is tell it which images are animated.

Change this line
const result = await background.composite([{ input: await overlay.toBuffer(), gravity: center }]).toBuffer();
To
const result = await background.composite([{ input: await overlay.toBuffer(), gravity: center , animated: true }]).toBuffer();
Notice the animated: true declaration for the overlay input.

Hopefully this helps.





相关问题
Free merge tools [closed]

I need free merge tool, in order to compare differences in 2 directories. I used Beyond Compare and Araxis Merge, but this tools are not free. Maybe you can recommend some other? I tried WinMerge, but ...

How to merge duplicates in 2D python arrays

I have a set of data similar to this: # Start_Time End_Time Call_Type Info 1 13:14:37.236 13:14:53.700 Ping1 RTT(Avr):160ms 2 13:14:58.955 13:15:29.984 Ping2 RTT(Avr):40ms ...

How is this a conflict

i m just testing git to find out if i could use it for my work. I ran into a problem that seems small but could become a real one with the real code. My file looks like: text.txt 1 2 3 ...

achieving a complex sort via Linq to Objects

I ve been asked to apply conditional sorting to a data set and I m trying to figure out how to achieve this via LINQ. In this particular domain, purchase orders can be marked as primary or secondary. ...

Git pull from several repos in one command

I d like to keep Git repositories on four machines synchronized, and all of them are private repos. Is it possible to set up a single Git repository to pull from the other three machines at the same ...

Problem in SVN merging branches into trunk

I have a trunk (A) and two branches (B and C). When I merge A with C its OK, after I merge A with B, the previous C its overwriten and my trunk don t have the C changes. What I want is A + B + C into ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

热门标签