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

Using websocket compression breaks the bot #3783

Closed tiritto closed 4 years ago

tiritto commented 4 years ago

Please describe the problem you are having in as much detail as possible: The bot seems to be unable to receive or emit events, becoming unresponsive for anything. However, the connection and verification are handled correctly since bot itself DOES login and shows up online on the member list. Moreover, if I regenerate its token while the bot is running, the bot is instantly throwing out access denied errors as soon as I regenerate the token, meaning that it apparently does upkeep the connection with Discord itself correctly.

Include a reproducible code sample here, if possible:

const Discord  = require('discord.js');
const client  = new Discord.Client({
    'ws': { compress: true }
});
client.login('super secret token');
client.on('ready', () => console.log("Hello there!"));

Hello there! will not be displayed as long as 'ws': { compress: true } is in use.

Further details:

vladfrangu commented 4 years ago

Here's a question. Why are you using the ws options? For compression, all you have to do is npm i zlib-sync (or your preferred package manager).. I don't actually know what the compress: true does, I'll have to shoot an eye at it

tiritto commented 4 years ago

Documentation doesn't say anything about negative effects nor discourages the use of it, so I feel like it's only natural to enable compression whenever possible for any network-related processes. It's casually listed under ClientOptions so I don't see anything wrong with customizing your bot configuration. Moreover, this setting was not causing any troubles for most of the time. I just noticed it's no longer working right on the master branch.

Also, according to documentation:

Whether to compress data sent on the connection (defaults to false for browsers)

The defaults to false for browsers part makes it sound like it's actually more encouraged to turn it on when not dealing with browser implementation.

vladfrangu commented 4 years ago

Here's your answer, asked in the Discord API server. If you want compression, just install zlib-sync.

image

tiritto commented 4 years ago

Well, that explains a lot. Thanks for your time! Can we change this issue from bug report to suggestion? I guess it would be a good idea to leave a notice in DiscordJS documentation for other people.