Discord.js: Raw event not present in typings

Created on 8 May 2020  Â·  5Comments  Â·  Source: discordjs/discord.js

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:

  • discord.js version: 12.2
  • Node.js version: 12.6, but running with ts-jest (tested with typescript 3.8.3 and 3.9.1-rc)
  • Operating system: windows 10
  • Priority this issue should have – please be realistic and elaborate if possible: idk
  • [x] I have also tested the issue on latest master, commit hash: a6510d6a6185b0b589e3aecb1b22b97bdf50fd04
unverified bug

Most helpful comment

The raw event is not supported (exists but discouraged) by discord.js. You can // @ts-ignore it or add it to your own typings.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  Â·  3Comments

Blumlaut picture Blumlaut  Â·  3Comments

Acaretia picture Acaretia  Â·  3Comments

Brawaru picture Brawaru  Â·  3Comments

tom-barnes picture tom-barnes  Â·  3Comments