discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
328 stars 112 forks source link

Type 'InternalDiscordGatewayAdapterCreator' is not assignable to type 'DiscordGatewayAdapterCreator' #166

Closed skyeredwood closed 2 years ago

skyeredwood commented 2 years ago

Please describe the problem you are having in as much detail as possible: I'm trying to simply create a connection using joinVoiceChannel using the discordjs.guide example and get an error every time:

experiment.ts:21:13 - error TS2322: Type 'InternalDiscordGatewayAdapterCreator' is not assignable to type 'DiscordGatewayAdapterCreator'.
  Types of parameters 'methods' and 'methods' are incompatible.
d-api-types/payloads/v9/voice").GatewayVoiceState) => void' is not assignable to type '(data: import("C:/Users/isaac/WebstormProjects/amethyst/node_modules/discord-api-types/payloads/v9/voice").GatewayVoiceState) => void'.
          Types of parameters 'data' and 'data' are incompatible.                                                      d-api-types/payloads/v9/voice").GatewayVoiceState) => void' is not assignable to
            Type 'import("C:/Users/isaac/WebstormProjects/amethyst/node_modules/discord-api-types/payloads/v9/voice").GayVoiceState) => void'.atewayVoiceState' is not assignable to type 'import("C:/Users/isaac/WebstormProjects/amethyst/node_modules/@discordjs/voice/node_modules/discord-api-types/payloads/v9/voice").GatewayVoiceState'.                                            atewayVoiceState' is not assignable to type 'import("C:/Users/isaac/WebstormProj
              Types of property 'guild_id' are incompatible.
                Type 'string' is not assignable to type '`${bigint}`'.

21             adapterCreator: stage.guild.voiceAdapterCreator
               ~~~~~~~~~~~~~~

  node_modules/@discordjs/voice/dist/index.d.ts:1259:5
    1259     adapterCreator: DiscordGatewayAdapterCreator;
             ~~~~~~~~~~~~~~
    The expected type comes from property 'adapterCreator' which is declared here on type 'JoinVoiceChannelOptions & CreateVoiceConnectionOptions'  
import { Message } from "discord.js";
import { joinVoiceChannel } from '@discordjs/voice'

const Discord = require('discord.js');
const client = new Discord.Client({ intents: new Discord.Intents(32767) })

client.login('ODE1OTQzNDY0NTE1OTI4MTM0.YDzwkQ.m0Ul5FyEUqcbLRs44ltvTN113F8')

client.on('ready', ready => {
    console.log("and we're off!")
})

client.on('messageCreate', async (message: Message) => {
    if (message.author === client.user) return;

    await message.guild.channels.create("Stage", {type: "GUILD_STAGE_VOICE"}).then(stage => {
        stage.guild.stageInstances.create(stage, {topic: "STAGE"})
        const connection = joinVoiceChannel({
            channelId: stage.id,
            guildId: stage.guild.id,
            adapterCreator: stage.guild.voiceAdapterCreator
        })
    })

})

Further details:

iim-ayush commented 2 years ago

Temporary Fix until it is rectified.

Just go to node_modules/discord.js/typings/index.d.ts

Then add this line at top :

import { DiscordGatewayAdapterCreator } from '@discordjs/voice';

Then search for voiceAdapterCreator in the same file and change it to :

  public readonly voiceAdapterCreator: DiscordGatewayAdapterCreator;
twlite commented 2 years ago

imo using stage.guild.voiceAdapterCreator as unknown as DiscordGatewayAdapterCreator is better than modifying source file

amishshah commented 2 years ago

Resolved in v0.5.6

mjmjelde commented 2 years ago

I still have this problem in versions 5.6 and 6.0

Resolved in v0.5.6

I still have this problem in 5.6 and 6.0

iim-ayush commented 2 years ago

I still have this problem in versions 5.6 and 6.0

Resolved in v0.5.6

I still have this problem in 5.6 and 6.0

If you are on ts, add //@tts-ignore on top of that line.

This is due to difference of discord-api-types version of discord.js and @discordjs/voice