Discord.js: Typing forever (channel.startTyping)

Created on 22 Jan 2018  Â·  16Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:

I'm forwarding typing events across different channels and sometimes the typing does not stop and keeps going on forever.

Include a reproducible code sample here, if possible:


// startTyping event and condition ->
channel.startTyping(3);

// stopTyping event and condition ->
channel.stopTyping(true);

// tried adding a setTimeout that calls stopTyping() ->
client.setTimeout(typingStopper, 2000, channel);

// and even a command to force stopping
// on comand ->
typingStopper(channel);

// typingStopper looks like this
const typingStopper = function(channel)
{
   channel.stopTyping(true);
};

So basically, startTyping is called a few times and doesn't stop even when stopTyping is called by: stopTyping event, stopTyping function, stopTyping command or stopTyping timer

Further details:

  • discord.js version: 1.13 stable
  • node.js version: 8.*
  • Operating system: tested on win7 and debian
  • Priority this issue should have – please be realistic and elaborate if possible:

  • [ ] I found this issue while running code on a __user account__

  • [ ] I have also tested the issue on latest master, commit hash:
low REST bug

Most helpful comment

Thanks a lot! (finally can rest in peace)

All 16 comments

🤔

This should be fixed by https://github.com/discordjs/discord.js/commit/8df1ac9920a20d74c7d5cd15ee0124f6e7236abc.

Calling startTyping a second (or more) time(s) created a new entry and overwrote the old one instead of just incrementing it.
Those older entries' timeouts couldn't be cleared anymore, this will now just increment/set the already existing entry and not create more anymore.

@SpaceEEC it seemed to have been fixed for a while but I realized the issue still exists - can you look into it?

Anything else to reproduce or still the old procedure?

Closing because it doesn't appear to be reproducible.

My bot have been encountering the same problem.

message.channel.startTyping();
//do my stuff here
message.channel.stopTyping(true);

when the above code is used on the affected channel, the typing indicator stopped briefly but began to restarted typing again after a few seconds.

I have been notified of this bug by the users over and over again.

@Maddoxkkm I think the problem is DM channels or cross-shard typing forwarding, make sure the channel exists/reachable before calling the startTyping - also add a timer of 5 seconds to cancel it in case stopTyping was not recognized to ensure it will stop.

this whole thing was triggered by this

bot.on('message', function(message){
//here goes the startTyping and stopTyping
})

so the channel must exist (because that's where the message come from, right?)

and this only happens in non-DM channels.... haven't had it happening in DM channels just yet.
shards is also out of the question - my bot is only in 500 servers, and I have no idea how to shard.

I might add another function to make sure it stops typing if it finds the bot to be typing after a few seconds.

@Maddoxkkm oh I forgot to mention that make sure you ignore bot messages otherwise it will cause a loop of typing - e.g:

bot.on('message', function(message){
   // ignore messages by bots
   if (message.author.bot) return;

   // otherwise, start typing
   message.channel.startTyping();

   // optional timeout after 5 seconds
   setTimeout(message.channel.stopTyping, 5000);

   // example to call stopTyping with callback/promise
   doSomething()
      .then(()=> message.channel.stopTyping())
      .catch(err => message.channel.stopTyping());
});

Edit: also callback the stopTyping method on callback errors

sorry for making things complicated
the startTyping and stopTyping only when certain commands are used. which shouldn't be triggered by every single message everyone sent.

Anyway new things came in.
image

    if(message.content.toUpperCase().startsWith(prefix.toUpperCase() + "ISTYPING")){
        message.channel.send(`Typing in this channel: ${SerBot.user.typingIn(message.channel)}`);
    }
    if(message.content.toUpperCase().startsWith(prefix.toUpperCase() + "STOPTYPING")){
        message.channel.stopTyping(true);
    }

Apparently this is something to do with the Typing status between the bot and Discord not synchronized?

There is only 1 instance of the bot running, not sharded

I now have a reproducible code for the Forever Typing issue: (at least it is reproducible on my side)

const Discord = require("discord.js");
const foreverTyping = new Discord.Client();

foreverTyping.on("message", function(message){
    if(message.content.toUpperCase().startsWith("F!FOREVERTYPING")){
        message.channel.startTyping();
        setTimeout(()=>{
            message.channel.send("Testing to ForeverTyping!");
            message.channel.stopTyping();
        },2000)
    }
});

foreverTyping.login("token here");

to activate this forever typing, just quickly send f!forevertyping twice in the same channel in quick succession.

After the bot stopped typing, it will begin forever typing after a few seconds.

I can reproduce the forever typing bug with that code on stable, but not on 11.3-dev.

so basically we will just have to wait?

For the next release, yes. (Or install the 11.3-dev branch from github directly)

Thanks a lot! (finally can rest in peace)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lombra picture Lombra  Â·  3Comments

tom-barnes picture tom-barnes  Â·  3Comments

iCrawl picture iCrawl  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments

kvn1351 picture kvn1351  Â·  3Comments