【问题标题】:Random quote command remodel随机报价命令改造
【发布时间】:2018-12-09 18:54:00
【问题描述】:

我对 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>"); 
}

【问题讨论】:

  • 抱歉,您发布的代码似乎与您的问题无关。你说的是哪个用户?什么命令?
  • 我猜reply 回复 给用户,channel.send 向频道发送消息?! I'm fairly new to JS ...那就先学了再问问题吧。

标签: javascript discord discord.js


【解决方案1】:

Message.reply() 在同一频道中发送带有提及标签的消息。如果你不想要提及标签,你必须在同一个频道发送消息,你可以用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)]);

【讨论】:

  • 谢谢!无论如何,当您键入命令时,您不必添加任何其他文本?例如,目前您必须执行 '!quote some-text-here' 抱歉打扰了
猜你喜欢
  • 1970-01-01
  • 2020-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 2016-05-10
相关资源
最近更新 更多