0

So what I want in the end is this:

user: "*cmd hello"

bot: "hello"

I tried replacing it, searched different ways to edit it, but nothing worked so far.

    if (receivedMessage.content.includes("*cmd")) {
    receivedMessage.content.replace('*cmd', ' ');
    receivedMessage.channel.send(receivedMessage.content);
    receivedMessage.channel.send("s/*cmd/-");
}    

(^found out that you can edit stuff by typing s/oldtext/newtext, but sadly it doesn't seem to work with the bot. Replacing didn't work, either.)

    if (receivedMessage.content.includes("*cmd")) {
    receivedMessage.channel.send(receivedMessage.content.text(text.replace('*cmd', ' '))); 
}    

(I tried more stuff, but I deleted it when it didn't work, and I don't think it'd help, anyway)

I'd really appreciate some help!

kreakiwi
  • 65
  • 3
  • 11
  • Possible duplicate of [How can I perform a str\_replace in JavaScript, replacing text in JavaScript?](https://stackoverflow.com/questions/5519368/how-can-i-perform-a-str-replace-in-javascript-replacing-text-in-javascript) – André Dec 18 '18 at 18:26

1 Answers1

1

string.replace() returns a string.
So, "This is a test".replace("This is a ", "") will return "test".

console.log("This is a test".replace("This is a ", ""));

With that in mind, this is what you need to use:

receivedMessage.channel.send(receivedMessage.content.replace('*cmd', ''));
André
  • 4,417
  • 4
  • 29
  • 56