discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

typingStart not working in dm on uncached channels with partials #4771

Closed Snokilo closed 3 years ago

Snokilo commented 4 years ago

The event detecting if a player start typing in a channel doesn't trigger in a dm channel

typingStart

Emitted whenever a user starts typing in a channel.

Nothing in the documentation precise it is not suppose to work

const Discord = require('discord.js');
const config = require('./config');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

// Not triggered by bot DM Channel
client.on('typingStart', (channel, user) => {
  console.log(channel)
}); 

client.login(config.token);

Further details:

Relevant client options:

almostSouji commented 4 years ago

https://github.com/discordjs/discord.js/blob/56e8ef2d38633154540748acb64f4c1305fcc6d3/src/client/websocket/handlers/TYPING_START.js#L11

The event can only emit on client if the channel is cached, discord.js otherwise drops the event (does not emit it). In this case this means you did not have a DM during the bots session from either side (you -> bot/ bot- > you), else the channel would be created/cached.

We do offer a feature called partials to still get these events, however in this case this seems to not fix it, which is the actual issue here (and why this should be kept open).


Modification of OP to reproduce the (now true) bug with partials enabled:

// enable partials:
const client = new Discord.Client({
    partials: ["CHANNEL", "USER"]
});

// [...]

// tracking the websocket event TYPING_START to exclude discord not emitting the event as cause 
client.ws.on("TYPING_START", d => {
    console.log("TYPING_START: ", d)
})

I will update as I find out more/potential fixes

NotSugden commented 4 years ago

the cause would seem to be the channel (and user) isnt added using *Manager.add, and instead retrieved using *Manager.cache.get @almostSouji

ref: https://github.com/discordjs/discord.js/blob/b0ab37ddc0614910e032ccf423816e106c3804e5/src/client/websocket/handlers/TYPING_START.js#L7-L8

almostSouji commented 4 years ago

I'm currently doubting we can do this at all, seeing that we need much more than the ID to properly handle typing events.

  1. We would need the _typing map to properly handle this, which can not be present on a universal CHANNEL partial - could solve that with a TEXTLIKE_CHANNEL - or whatever partial, however
  2. we can receive this event for any type of channel as per API specification, including channels where it does not make a lot - or any sense, which leads us to:
  3. the payload just includes channel_id, so we can't know what type of channel this emits on, we can also not just assume it is a text based channel due to 2.
Snokilo commented 4 years ago

I have created a PR fixing it https://github.com/discordjs/discord.js/pull/4772#issue-477205672

almostSouji commented 4 years ago

Not auto-fetching data is a deliberate choice in the libraries design

iCrawl commented 3 years ago

This issue has been stale for a while, if this problem still exists or you can still easily replicate it on v13 (current master or discord.js@dev on NPM), please reopen it as a new issue.