【问题标题】:client.startTyping is not a function (Discord.JS)client.startTyping 不是函数 (Discord.JS)
【发布时间】:2017-11-28 19:37:18
【问题描述】:

我正在尝试使用 NodeJS 和 DiscordJS 创建一个 Discord 机器人。但是,当我尝试使用client.startTyping() 函数时,参考https://github.com/hydrabolt/discord.js/issues/440http://discordjs.readthedocs.io/en/latest/docs_client.html,似乎返回一个错误,说该函数不存在。我该如何解决这个问题?

https://pastebin.com/S25fiJaZ(完整代码)

client.startTyping(message.channel);
for (i = 0; i < (times + 1); i++) {
    message.channel.sendMessage(msg);
}
client.stopTyping(message.channel);

这是错误:

TypeError: client.startTyping is not a function
    at Client.client.on (/home/ty/discordbot/index.js:68:16)
    at emitOne (events.js:115:13)
    at Client.emit (events.js:210:7)
    at MessageCreateHandler.handle (/home/ty/discordbot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (/home/ty/discordbot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:102:65)
    at WebSocketConnection.onPacket (/home/ty/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:325:35)
    at WebSocketConnection.onMessage (/home/ty/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:288:17)
    at WebSocket.onMessage (/home/ty/discordbot/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:125:13)
    at WebSocket.emit (events.js:213:7)

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    因为正如错误消息所说,客户端对象没有名为startTyping 的函数。该函数位于文本通道对象中,如 here 所示。此外,sendMessage 已被弃用。请改用发送。

    message.channel.startTyping();
    for (i = 0; i < (times + 1); i++) {
        message.channel.send(msg);
    }
    message.channel.stopTyping();
    

    【讨论】:

      【解决方案2】:

      这是因为client没有startTyping功能,channels有startTyping通道,所以可以这样做:

      message.channel.startTyping()
      

      您可以使用 .stopTyping() 停止输入,这样您也可以这样做:

      message.channel.stopTyping()
      

      【讨论】:

        【解决方案3】:

        discord.js V13 中,TextChannel.startTyping()TextChannel.stopTyping() 已被替换为单数 TextChannel.sendTyping()。此方法在 10 秒后或发送消息时自动停止输入。 如docs 中所见,用于更新到 V13

        【讨论】:

          【解决方案4】:

          startTyping 函数应该在通道而不是客户端上调用:

          message.channel.startTyping();
          setTimeout(function(){
              message.channel.stopTyping();
              message.channel.send(msg);
          }, times);
          

          【讨论】:

            猜你喜欢
            • 2020-12-31
            • 2020-12-07
            • 2020-08-23
            • 2020-01-22
            • 2020-11-13
            • 2021-06-15
            • 2020-12-22
            • 2021-01-27
            • 2021-06-17
            相关资源
            最近更新 更多