I am making a discord bot and I am trying to save strings into an array and send it if the right command is sent. Here is the code:
client.on('messageCreate', (msg) => {
if(!msg.content.startsWith(commandChar)) return;
const args = msg.content.slice(1).split(' ');
const cmdBody = msg.content.slice(msg.content.indexOf(' '));
const cmd = args.shift().toLowerCase();
switch(cmd) {
case 'new':
quotes.push(cmdBody);
msg.channel.send('Quote added! The Quote Number is ' + quotes.length);
break;
case 'find':
if(isNaN(cmdBody))
cmdBody--;
try {
text = quotes[cmdBody]
msg.channel.send(text);
}
catch {
msg.channel.send('There is no quote corresponding to the number' + (cmdBody + 1) + '.');
}
break;
case 'changeCommandChar':
if(cmdBody.length === 1) {
commandChar = cmdBody;
msg.channel.send('Command Character changed! The new command Character is ' + commandChar);
}
break;
}
});
Here is the error:
RequestHandler.js:350 throw new DiscordAPIError(data, res.status, request);
DiscordAPIError: Cannot send an empty message