【问题标题】:Make discord bot (js) echo message, but removing the command from the message?制作不和谐机器人(js)回显消息,但从消息中删除命令?
【发布时间】:2019-05-19 05:08:02
【问题描述】:

所以我最后想要的是这样的:

用户:“*cmd 你好”

机器人:“你好”

我尝试替换它,搜索了不同的方法来编辑它,但到目前为止没有任何效果。

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

(^发现您可以通过键入 s/oldtext/newtext 来编辑内容,但遗憾的是它似乎不适用于机器人。替换也不起作用。)

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

(我尝试了更多的东西,但是当它不起作用时我将其删除,无论如何我认为它没有帮助)

非常感谢一些帮助!

【问题讨论】:

标签: node.js bots discord.js


【解决方案1】:

string.replace() 返回一个字符串。
所以,"This is a test".replace("This is a ", "") 将返回“test”。

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

考虑到这一点,这就是您需要使用的:

receivedMessage.channel.send(receivedMessage.content.replace('*cmd', ''));

【讨论】:

  • 很遗憾,我收到了一个错误。 “ReferenceError:文本未定义”
  • 好的,我只是在没有“.text”的情况下尝试过它,它可以工作。耶!谢谢!
猜你喜欢
  • 2018-05-02
  • 2020-12-23
  • 2021-05-29
  • 2020-10-03
  • 1970-01-01
  • 2021-07-25
  • 1970-01-01
  • 2018-11-19
  • 2020-12-15
相关资源
最近更新 更多