随机引用命令改造

Random quote command remodel

我是 JS 的新手,我找到了一段用于 Discord 机器人的代码,我想知道如何才能做到当有人输入 !quote 时,响应不会标记用户,并且需要与用户的命令一起键入其他文本。谢谢

if (command == "quote") { 
    if (args[1] != null) message.reply(quote[Math.floor(Math.random() * quote.length).toString(16)]); // if args[1], post random answer
    else message.channel.send("!quote <your text here>"); 
}

Message.reply() sends a message in the same channel with a mention tag. If you don't want the mention tag, you have to send a message in the same channel, and you can do that with message.channel.send()

您的代码应如下所示:

if (command == "quote") { 
  if (args[1] != null) message.channel.send(quote[Math.floor(Math.random() * quote.length).toString(16)]); // if args[1], post random answer
  else message.channel.send("!quote <your text here>"); 
}

如果你不想检查任何额外的文本,你可以去掉 if/else 检查,只留下 message.channel.send():

if (command == "quote") message.channel.send(quote[Math.floor(Math.random() * quote.length).toString(16)]);