Search code examples
discord.jsprefix

Discord.js how to ignore a specific text and send the rest


I'm trying to make an emoji library bot, which is private. The issue I'm facing is here:

  case 'madiamond' :
  case 'mashiningdiamond' :
    message.channel.send(`**${message.author.tag}** : <a:shiningdiamond:725331059369181284> ${message.content}`)
    message.delete({timeout: 1000});
  break;

I want to make it so it ignores the prefix and command, which is e!madiamond. The issue I'm facing is that when I use this command in Discord, it shows the message like this:

What I get:

Username#0000 : (the emoji) e!madiamond user message

What I want:

Username#0000 : (the emoji) user message


Solution

  • You can use String.split() and Array.slice() to dynamically remove the command portion of message.content. Then use Array.join() to join the array back into a string.

    case 'madiamond' :
    case 'mashiningdiamond' :
       const filteredContent = message.content.split(' ').slice(1).join(' ');
       message.channel.send(`**${message.author.tag}** : <a:shiningdiamond:725331059369181284> ${filteredContent}`);
       message.delete({timeout: 10});
    break;