Please describe the problem you are having in as much detail as possible:
client.on("raw"...) throws an error when using typescript in strict mode
Include a reproducible code sample here, if possible:
typescript:
import { Client } from "discord.js";
const client = new Client();
client.on("raw", (pk) => {
console.log(pk);
});
Error message
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:5:11 - error TS2345: Argument of type '"raw"' is not assignable to parameter of type '"channelCreate" | "channelDelete" | "channelPinsUpdate" | "channelUpdate" | "debug" | "warn" | "disconnect" | "emojiCreate" | "emojiDelete" | "emojiUpdate" | "error" | "guildBanAdd" | ... 37 more ... | "shardResume"'.
5 client.on("raw", (pk) => {
~~~~~
at createTSError (C:\Users\kkm\Workspace\moonbot\node_modules\ts-node\src\index.ts:434:12)
at reportTSError (C:\Users\kkm\Workspace\moonbot\node_modules\ts-node\src\index.ts:438:19)
at getOutput (C:\Users\kkm\Workspace\moonbot\node_modules\ts-node\src\index.ts:578:36)
at Object.compile (C:\Users\kkm\Workspace\moonbot\node_modules\ts-node\src\index.ts:775:32)
at Module.m._compile (C:\Users\kkm\Workspace\moonbot\node_modules\ts-node\src\index.ts:858:43)
at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\kkm\Workspace\moonbot\node_modules\ts-node\src\index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
The same code run using javascript works perfectly
Further details:
The raw event is not supported (exists but discouraged) by discord.js. You can // @ts-ignore it or add it to your own typings.
Should also be noted that as of v12 raw is totally uneeded with the addition of partials. Besides debugging problems with the lib itself (perhaps the packet handlers) there's seriously no use case for it.
@didinele I am trying to use lavalink for playing audio, and I need to handle VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE events, however interface from client.on('voiceStateUpdate') in incompatible with lavalinks voiceStateUpdate method and I don't see ClientEvent for voiceServerUpdate event
This is getting beyond the issue tracker, move to the Discord server
You want to take a look at the WebSocketManager then, you can listen to the raw dispatches there.
Most helpful comment
The
rawevent is not supported (exists but discouraged) by discord.js. You can// @ts-ignoreit or add it to your own typings.