This is my code for a webhook discord alert bot. I used discord.js and the channel's webhooks. I used readline-sync for the input at the console but when I iterate through the answer at console to determine the embed colour, all signals show yellow from the last iteration for some reason.
const { MessageEmbed, WebhookClient } = require('discord.js');
const readline = require('readline-sync')
const webhookClient = new WebhookClient({ id: '', token: '' });
var signal = readline.question("Signal: ")
if (signal.content === "SELL")
{
const embed = new MessageEmbed()
.setTitle(signal)
.setColor('RED')
.setFooter({
text: "test"
})
webhookClient.send({
content: 'Webhook test',
username: "Logan's Signals",
avatarURL: 'https://i.imgur.com/AfFp7pu.png',
embeds: [embed],
});
}
else if (signal.content === "BUY")
{
const embed = new MessageEmbed()
.setTitle(signal)
.setColor('GREEN')
.setFooter({
text: "test"
})
webhookClient.send({
content: 'Webhook test',
username: "Logan's Signals",
avatarURL: 'https://i.imgur.com/AfFp7pu.png',
embeds: [embed],
});
}
else
{
const embed = new MessageEmbed()
.setTitle(signal)
.setColor('YELLOW')
.setFooter({
text: "test"
})
webhookClient.send({
content: 'Webhook test',
username: "Logan's Signals",
avatarURL: 'https://i.imgur.com/AfFp7pu.png',
embeds: [embed],
});
}