Sends a animated gif welcoming new member in your selected channel.
//make sure your timeout is set to 30000 or above. You can do this in the advance setting in your project(located lower left corner) and changing the Timeout value to 30000.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const GIFEncoder = require('gif-encoder-2');
const jimp = require('jimp');
const size = {
width: 360,
height: 98,
};
const frames = 30;
const banner_images = [
'https://cdn.discordapp.com/attachments/883314301887184907/883315019691995166/frame_00_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315032778223626/frame_01_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315047068237854/frame_02_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315191964643359/frame_03_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315206393069588/frame_04_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315302945943572/frame_05_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315330368294932/frame_06_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315343240613888/frame_07_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315363889176616/frame_08_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315377742962718/frame_09_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315392523669514/frame_10_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315417790185522/frame_11_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315439340494898/frame_12_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315456927223818/frame_13_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315480390139904/frame_14_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315495628058654/frame_15_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315520181506088/frame_16_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315536900014080/frame_17_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315555145224192/frame_18_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315577509269544/frame_19_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315596954046464/frame_20_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315611051098152/frame_21_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315629552173066/frame_22_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315653023531018/frame_23_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315675949588490/frame_24_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315698351341588/frame_25_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315717972303872/frame_26_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315746950766662/frame_27_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315759282012170/frame_28_delay-0.04s.gif',
'https://cdn.discordapp.com/attachments/883314301887184907/883315773521690654/frame_29_delay-0.04s.gif',
];
const encoder = new GIFEncoder(size.width, size.height);
encoder.setDelay(20);
encoder.start();
for (let i = 0; i < frames; i++) {
let avatar = await jimp.read(
`https://cdn.discordapp.com/avatars/${context.params.event.user.id}/${context.params.event.user.avatar}.png`
);
avatar.circle();
avatar.resize(80, 80);
let banner = await jimp.read(`${banner_images[i]}`);
banner.composite(avatar, 122.5, 0);
let font = await jimp.loadFont(jimp.FONT_SANS_12_BLACK);
banner.print(
font,
0,
40,
{
text: `Welcome, ${context.params.event.user.username}#${context.params.event.user.discriminator} to the server!`,
alignmentX: jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: jimp.VERTICAL_ALIGN_MIDDLE,
},
360,
98
);
encoder.addFrame(banner.bitmap.data);
}
encoder.finish();
const buffer = encoder.out.getData();
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${process.env.welcomeChannel_id}`,
content: `Welcome, <@${context.params.event.user.id}>`,
file: buffer,
filename: `banner.gif`,
});