kreakiwi
kreakiwi

Reputation: 65

Make discord bot (js) echo message, but removing the command from the message?

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!

Upvotes: 0

Views: 4177

Answers (1)

André
André

Reputation: 4497

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', ''));

Upvotes: 1

Related Questions