client.startTyping 不是函数 (Discord.JS)
client.startTyping is not a function (Discord.JS)
我正在尝试使用 NodeJS 和 DiscordJS 创建一个 Discord 机器人。但是,当我尝试使用 client.startTyping()
函数时,引用 https://github.com/hydrabolt/discord.js/issues/440 and http://discordjs.readthedocs.io/en/latest/docs_client.html,它似乎 return 一个错误,指出该函数不存在。我该如何解决这个问题?
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();
这是因为client
没有startTyping功能,频道有startTyping频道,所以你可以这样做:
message.channel.startTyping()
您可以使用 .stopTyping() 停止输入,这样您也可以这样做:
message.channel.stopTyping()
startTyping
函数应该在通道而不是客户端上调用:
message.channel.startTyping();
setTimeout(function(){
message.channel.stopTyping();
message.channel.send(msg);
}, times);
在discord.jsV13TextChannel.startTyping()
和TextChannel.stopTyping()
中被单数TextChannel.sendTyping()
取代。此方法会在 10 秒后或发送消息时自动停止输入。
如更新到 V13docs 中所见
我正在尝试使用 NodeJS 和 DiscordJS 创建一个 Discord 机器人。但是,当我尝试使用 client.startTyping()
函数时,引用 https://github.com/hydrabolt/discord.js/issues/440 and http://discordjs.readthedocs.io/en/latest/docs_client.html,它似乎 return 一个错误,指出该函数不存在。我该如何解决这个问题?
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();
这是因为client
没有startTyping功能,频道有startTyping频道,所以你可以这样做:
message.channel.startTyping()
您可以使用 .stopTyping() 停止输入,这样您也可以这样做:
message.channel.stopTyping()
startTyping
函数应该在通道而不是客户端上调用:
message.channel.startTyping();
setTimeout(function(){
message.channel.stopTyping();
message.channel.send(msg);
}, times);
在discord.jsV13TextChannel.startTyping()
和TextChannel.stopTyping()
中被单数TextChannel.sendTyping()
取代。此方法会在 10 秒后或发送消息时自动停止输入。
如更新到 V13docs 中所见