Search code examples
argumentsslicediscord.jsargs

Discord.js Announce Command Slice Issue with Args


iv made an announce command for my bot, i have it outputting the contents of the message to a RichEmbed.

I have it set in IF statement

If users mentioned first then it removes the mention and sends it to the channel and displays embed with contents (args.slice(2))

ELSE just send the embed with args.slice(1) removing the command.

My problem is that they either both slice(1) or both slice(2) , despite me having them set differently

if (!user);
const embed = new Discord.MessageEmbed()
    .setTitle(`${(args.slice(1).join(" "))}`, 'https://i.gyazo.com/898806671312f3585209cf0fd69341006.jpg')
    .setColor(0x320b52)
    .setTimestamp()
    .setFooter('Requested by ' + message.author.tag, 'https://i.gyazo.com/898806671312f3585209cf0fd69341006.jpg')
message.channel.send(embed);

}
else {

    message.channel.send("<@" + user.id + ">")

    const embed = new Discord.MessageEmbed()
        .setTitle(`${(args.slice(2).join(" "))}`, 'https://i.gyazo.com/898806671312f358509cf0fd69341006.jpg')
        .setColor(0x320b52)
        .setTimestamp()
        .setFooter('Requested by ' + message.author.tag, 'https://i.gyazo.com/898806671312f358509cf0fd69341006.jpg')
    message.channel.send(embed);


}

Solution

  • Replace the ; in your first line with a {:

    if (!user) {