【问题标题】:My discord bot answer the prefix even without the command即使没有命令,我的不和谐机器人也会回答前缀
【发布时间】:2020-12-05 13:10:15
【问题描述】:

“/tts”也不起作用,即使有 tss 权限,bot 也只能写入。

const prefix = "!";


bot.on('message', message => {
if (message.author.bot || !message.content.startsWith(prefix)) return;

const args = message.content.slice(prefix.length).split(new RegExp(' ', 'g'));
const command = args.shift().toLowerCase();

const user = message.author;

  if (command == "stretch" || "sr"){
    message.channel.send(user.username + ' your stretch reminder was 

activated!', tts=true);
        }
  });

【问题讨论】:

  • 尝试删除不必要的 { } 从返回开始;
  • 我做到了,但遗憾的是问题仍然存在。我还删除了部分代码(你可以看到我编辑了帖子),问题仍然存在所以它与我取出的部分无关。看起来是对的,idk什么出了问题。
  • 现在至少它只是回答正确的前缀,但仍然在没有任何命令的情况下回答它。

标签: node.js discord bots discord.js


【解决方案1】:

1。即使没有命令,机器人也会回答

问题来自command == "stretch" || "sr"。它检查commandstretch 还是sr 是否存在。由于 'sr' 不是未定义的,因此它始终为真,并且机器人将使用这 2 个命令以外的命令进行响应。所以,你可以把代码改成command == 'stretch' || command = 'sr'

2。 tts 不工作

没有问题。这是不和谐的错误,没有任何可用的信息。

【讨论】:

  • 伙计,你太棒了,它真的修好了!非常感谢!当我获得 15 名声望时,我会回来为你的答案投票!
【解决方案2】:

问题在于split
拆分接受正则表达式,但这不是插入标志的正确方法
试试split(new RegExp(' ', 'g'))

【讨论】:

  • 我改了,代码还能用,但还是一样的问题。哦,我还不能投票,但我试过了!谢谢你的帮助!
猜你喜欢
  • 2021-11-15
  • 2023-03-20
  • 1970-01-01
  • 2021-10-30
  • 1970-01-01
  • 2021-11-21
  • 2017-10-15
  • 2021-06-19
  • 2020-06-01
相关资源
最近更新 更多