discordjs / discord.js

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

TypeError: options.adapterCreator is not a function #9398

Closed j-youngberg closed 1 year ago

j-youngberg commented 1 year ago

Which package is this bug report for?

voice

Issue description

Hello! Thank you for discordjs! Version 12 was amazing. I am currently in the process of re-writing a soundboard music bot (a bot that connects to a separate website with buttons that play sounds in discord/a channel).

The bot is built with nodejs and express. I have the bot join a voice channel when any button is pressed (with channel and guild ids sent to express), but I am having an issue getting it to join with the code provided in the Voice Connections Documentation. When I set it up in this new format, passing in the channel and server/guild ids (which I have verified are coming in properly) I get the following error related to the voiceAdapterCreator: image

Would anyone be able to provide some guidance or a fix with this issue? Thank you and my apologies if it is just user error :).

Code sample

// Join the voice channel sent with the button click
        const { joinVoiceChannel } = require('@discordjs/voice');

        // Get the channel by id
        const channel = client.channels.fetch(req.body.channelID)
        .then(channel => console.log(channel.name))
        .catch(console.error);

        // Get the guild(server) by id
        const guild = client.guilds.fetch(req.body.guildID)
        .then(guild => console.log(guild.name))
        .catch(console.error);

        const connection = joinVoiceChannel({
        channelId: channel.id,
        guildId: guild.id,      
        adapterCreator: guild.voiceAdapterCreator,
        });

Package version

$ npm list effectbot@1.0.0 C:\EffectBot ├── @discordjs/builders@1.6.1 ├── @discordjs/opus@0.9.0 ├── @discordjs/rest@1.7.0 ├── @discordjs/voice@0.16.0 ├── ascii-table@0.0.9 ├── discord-api-types@0.37.38 ├── discord-player@6.1.1 ├── discord.js@14.9.0 ├── dotenv@16.0.3 ├── express@4.18.2 └── glob@9.3.4

Node.js version

$ node -v v18.15.0

Operating system

Windows 11

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds

I have tested this issue on a development release

discord.js@14.9.1-dev.1681603798-01949d6.0

Qjuh commented 1 year ago

Your channel and guild variables are both Promise<void> there because of your use of .then(..) So you need to adjust your promise handling. You also don’t wait for them to resolve.

j-youngberg commented 1 year ago

Oh dear... I was afraid this might be user error 🤦‍♂️... Thank you so much for this response. From it pointing me in the right direction I was able to come up with this, which does what I was looking for (joins the channel), and I will be writing it to play a specific sound next based on the button pressed:

// Join the voice channel sent with the button click
        const { joinVoiceChannel } = require('@discordjs/voice');

        // Go get the server
        client.guilds.fetch(req.body.guildID).then(guild => {

          // Go get the channel
          client.channels.fetch(req.body.channelID).then(channel => {

            console.log(guild.name);
            console.log(channel.name);

            //Join Channel
            const connection = joinVoiceChannel({
            channelId: channel.id,
            guildId: guild.id,
            adapterCreator: guild.voiceAdapterCreator,
            });

          });

        });

P.S. I realize (now that I know that this was not a bug) that this was probably posted in the wrong place, please let me know if there is somewhere else that you would prefer that questions like this be asked. Otherwise thanks again and hopefully this comment will help someone else in a similar situation.

Jiralite commented 1 year ago

You can join our support server and ask questions in our support channels!