This snippet will show you how you can make an embed message change color with the message.update api as well as a sleep function. To start to command to !embed and watch the colors change!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//Defines the sleep function which will make it wait 2 seconds between each change
let sleep = async (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms || 0);
});
};
//Defines the original message which has a red color
let message = await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embeds: [
{
type: `rich`,
title: `Color changing embed!`,
description: `This is a pretty sweet color changing embed message!`,
color: 0xff0000, //<--Color is red
},
],
});
//Calls sleep to wait 2 seconds before it continues
await sleep(200);
//Updates the message with the new color, orange
await lib.discord.channels['@0.3.0'].messages.update({
message_id: `${message.id}`,
channel_id: `${context.params.event.channel_id}`,
embeds: [
{
type: `rich`,
title: `Color changing embed!`,
description: `This is a pretty sweet color changing embed message!`,
color: 0xff9300, //<--Color is orange
},
],
});
await sleep(200);
await lib.discord.channels['@0.3.0'].messages.update({
message_id: `${message.id}`,
channel_id: `${context.params.event.channel_id}`,
embeds: [
{
type: `rich`,
title: `Color changing embed!`,
description: `This is a pretty sweet color changing embed message!`,
color: 0xffdc00, //<--Color is yellow
},
],
});
await sleep(200);
await lib.discord.channels['@0.3.0'].messages.update({
message_id: `${message.id}`,
channel_id: `${context.params.event.channel_id}`,
embeds: [
{
type: `rich`,
title: `Color changing embed!`,
description: `This is a pretty sweet color changing embed message!`,
color: 0x00ff00, //<--Color is green
},
],
});
await sleep(200);
await lib.discord.channels['@0.3.0'].messages.update({
message_id: `${message.id}`,
channel_id: `${context.params.event.channel_id}`,
embeds: [
{
type: `rich`,
title: `Color changing embed!`,
description: `This is a pretty sweet color changing embed message!`,
color: 0x0027ff, //<--Color is blue
},
],
});
await sleep(200);
await lib.discord.channels['@0.3.0'].messages.update({
message_id: `${message.id}`,
channel_id: `${context.params.event.channel_id}`,
embeds: [
{
type: `rich`,
title: `Color changing embed!`,
description: `This is a pretty sweet color changing embed message!`,
color: 0x8b00ff, //<--Color is purple
},
],
});