I’m relatively inexperienced with JavaScript, so your patience is appreciated. I’m developing a command for my Discord Bot that triggers with ‘!records’. I want the Bot to respond with a RichEmbed that presents two selectable options. Here’s the code snippet I have:
if (message.content.startsWith(config.prefix + 'records')) {
const richEmbed = new Discord.RichEmbed()
.setTitle('D E I C I D E Records')
.setAuthor('D E I C I D E', 'https://example.com/logo.png')
.setColor(3447003)
.setDescription('Please choose an option.')
.setTimestamp()
.addField('1. Raid Victories', 'Reply with "1" for Raid Victories.')
.addField('2. Defense Victories', 'Reply with "2" for Defense Victories.');
message.channel.send({embed: richEmbed});
message.channel.awaitMessages(res => res.content === '1', {
max: 1,
time: 10000,
errors: ['Time expired!'],
});
message.channel.send(drecords.RaidWins);
message.channel.awaitMessages(res => res.content === '2', {
max: 1,
time: 10000,
errors: ['Time expired!'],
});
message.channel.send(drecords.DefenseWins);
}
Currently, when ‘!records’ is executed, the Bot sends the RichEmbed but also immediately sends the records instead of waiting for a selection. Could someone explain what I’m doing wrong?
Additionally, I’d like to create a single command to update the records without manually editing the Bot’s files. My current code for updating the records looks like this:
if (message.content.startsWith(config.prefix + 'updateraids')) {
let updatedRecord = message.content.split(" ").slice(1)[0];
drecords.RaidWins = updatedRecord;
fs.writeFile('./drecords.json', JSON.stringify(drecords), (err) => console.error);
}
if (message.content.startsWith(config.prefix + 'updatedefenses')) {
let updatedRecord = message.content.split(" ").slice(1)[1];
drecords.DefenseWins = updatedRecord;
fs.writeFile('./drecords.json', JSON.stringify(drecords), (err) => console.error);
}
The issue is that when I use commands like ‘!updatedefenses DefenseWin2’, it replaces the existing entry instead of adding to it. How can I modify it so that entries can be either added or removed? Thanks for any advice, as I’ve been researching this extensively with no success.