问题描述
所以我最终想要的是这个
So what I want in the end is this:
用户:"* cmd你好"
user: "*cmd 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/-");
}
(^发现您可以通过键入s/oldtext/newtext来编辑内容,但遗憾的是它似乎不适用于该机器人.替换也不起作用.)
(^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)
我非常感谢您的帮助!
推荐答案
string.replace()返回一个字符串.
因此,这是一个测试".replace(这是一个,"")
将返回"test".
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', ''));
这篇关于使不和谐的bot(js)回显消息,但是从消息中删除命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!