我正在尝试使用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)

最佳答案

因为如错误消息所述,客户端对象没有名为startTyping的功能。该功能在文本通道对象中,如here所示。另外,不建议使用sendMessage。使用发送代替。

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

09-18 04:43