问题
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!
回答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', ''));
来源:https://stackoverflow.com/questions/53838838/make-discord-bot-js-echo-message-but-removing-the-command-from-the-message