【问题标题】:How do I use readline for Discord Bots?如何将 readline 用于 Discord Bots?
【发布时间】:2019-10-20 04:15:14
【问题描述】:

在尝试制作我的 Discord Bot 时,我遇到了另一个问题。我正在尝试让所有者让机器人在公告部分为我说些什么,这样它就不会显示为我的名字。

我已经尝试过 readline 接口(虽然我不知道我是否做得正确)并且我尝试过使用不同的方法来制作变量(const、var)。

if(message.member.roles.find(r => r.name === "Owner")){
  return message.reply("What would you like to say?")
  const dm = message.content;
  return message.reply("$dm")

我希望机器人对我所说的任何内容做出回应。所以,如果我输入 The Server Is Going Down Soon! 那么机器人应该回复我(在这种情况下)。

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    当您调用return 时,您正在结束正在编写的函数的执行。

    在这种情况下,

    if(message.member.roles.find(r => r.name === "Owner")){
      return message.reply("What would you like to say?") // the current function stops
      const dm = message.content; // this line never executes
      return message.reply("$dm")
    

    您将不得不等待我认为正在响应某种命令的用户的响应

    if (message.member.roles.find(r => r.name === "Owner")) {
        await message.reply("What would you like to say?"); // Send the request
        // Wait for the person who sent the original message to send another message
        let userMessages = await message.channel
            .awaitMessages(m => m.id === message.member.id, { max: 1 }); 
        let userMessage = userMessages.first()
        // Reply with the message they sent
        return message.member.reply(userMessage.content);
    

    【讨论】:

    • 在控制台中显示,SyntaxError: await is only valid in async function
    • 那么显然你必须让你的函数异步
    猜你喜欢
    • 2021-10-07
    • 2019-03-15
    • 2021-06-11
    • 1970-01-01
    • 2014-04-19
    • 2021-07-20
    • 2023-03-24
    • 2017-06-24
    • 1970-01-01
    相关资源
    最近更新 更多