Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  178] [ 4]  / answers: 1 / hits: 15592  / 7 Years ago, mon, june 26, 2017, 12:00:00

I am trying to create a Discord bot using NodeJS and DiscordJS. However, when I try to use the client.startTyping() function, referring to https://github.com/hydrabolt/discord.js/issues/440 and http://discordjs.readthedocs.io/en/latest/docs_client.html, it seems to return an error saying the function does not exist. How can I fix this?



https://pastebin.com/S25fiJaZ (full code)



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


This is the error:



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)

More From » node.js

 Answers
15

Because as the error message says, the client object has no function called startTyping. That function is in the text channel object as seen here. Also, sendMessage is deprecated. Use send instead.



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

[#57303] Friday, June 23, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billt

Total Points: 608
Total Questions: 100
Total Answers: 87

Location: Cape Verde
Member since Fri, Nov 27, 2020
4 Years ago
billt questions
Fri, Sep 10, 21, 00:00, 3 Years ago
Tue, Aug 18, 20, 00:00, 4 Years ago
Sat, Apr 6, 19, 00:00, 5 Years ago
;