-2

I got a problem here where i cant find out how i make so it will remove the !suggest in the message thats gonna be sent im trying to make it so when someone uses !suggest {suggestion} in the specific channel a message will be sent in the #suggestions channel ive got the specific channel up i just want to remove so instead of the bot saying "@user#1234 have suggested !suggest add a goodbye command" it will only say "@user#1234 have suggested: add a goodbye command" basically just removing !suggest heres the code its JavaScript

//Suggestions
client.on("message", message => {
if (message.content.startsWith("!suggest")){
return client.channels.get('514917785248202773').send(message.author.tag+" 
suggested " + message.content)
}
});

how would i make it so it removes the !suggest part only? cant find anything on here or internet at all

Lioness100
  • 8,260
  • 6
  • 18
  • 49
  • 1
    Possible duplicate of [How to remove text from a string in JavaScript?](https://stackoverflow.com/questions/10398931/how-to-remove-text-from-a-string-in-javascript) – takendarkk Nov 21 '18 at 22:39
  • It didnt really fix the problem with that i had to change alot of the coding in the replace but it was easy to do i just had a problem finding what the code was i didnt find that link when i originally searched for it thanks for mentioning it – The Light Blue Gamer Nov 21 '18 at 23:12

2 Answers2

0

A possibility is to split the message on every space (' '), removing the first element (which is always the command), and recombining the string array.

Example:

let message = "!suggest add a goodbye command"
const args = message.trim().split(' ');
args.shift();
console.log(args.join(' '));
T. Dirks
  • 3,566
  • 1
  • 19
  • 34
0
client.on('message', msg => {
if(msg.content.startsWith('!suggest')) {
let message = msg.content.split(" ");
const suggestion = message[1];
client.channels.get('514917785248202773').send(message.author.tag+" 
suggested " + suggestion)
}
}

this makes 'message' an array

MrMythical
  • 34
  • 1