discord.js help

if (message.content.startsWith('hi')) {
const last_message = await message.channel.messages.fetch({ limit: 2 });
const last_embed = last_message.last().embeds[0];

let color_index = 0;
if (last_embed && last_embed.color && colors.includes(last_embed.color)) {
const last_color_index = colors.indexOf(last_embed.color);
color_index = (last_color_index + 1) % colors.length;
} else {
color_index = colors.length - 1; // Set the initial color to the last color in the array
}

const next_color_index = (color_index + 1) % colors.length;
const embed = new EmbedBuilder()
.setDescription(`Welcome to Snoopal, ${message.author}!`)
.setColor(colors[next_color_index]);
message.channel.send({ embeds: [embed] });
}
if (message.content.startsWith('hi')) {
const last_message = await message.channel.messages.fetch({ limit: 2 });
const last_embed = last_message.last().embeds[0];

let color_index = 0;
if (last_embed && last_embed.color && colors.includes(last_embed.color)) {
const last_color_index = colors.indexOf(last_embed.color);
color_index = (last_color_index + 1) % colors.length;
} else {
color_index = colors.length - 1; // Set the initial color to the last color in the array
}

const next_color_index = (color_index + 1) % colors.length;
const embed = new EmbedBuilder()
.setDescription(`Welcome to Snoopal, ${message.author}!`)
.setColor(colors[next_color_index]);
message.channel.send({ embeds: [embed] });
}
I have this array of HEX color codesand the bot is supposed to take the last embed color in the channel, find it in the array and add the next one to the new embed but all it does is the color_index keeps returning 0 so it always returns the first color code from the array
2 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Dynamic
DynamicOP10mo ago
[email protected] Node v16.13.0 yes
Want results from more Discord servers?
Add your server