#First time using DJS/VC

57 messages · Page 1 of 1 (latest)

warm gustBOT
#
  • What are your intents? GuildVoiceStates is required to receive voice data!
  • Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice.
  • Try looking at common examples: https://github.com/discordjs/voice-examples.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
opal crest
#

it returns ```
An error occurred: Cannot read properties of undefined (reading 'ended')

#

its my first time using the voice part of DJS

flat grotto
#

can you show the full error

opal crest
#

yeah hang on a minute

#
An error occurred: TypeError: Cannot read properties of undefined (reading 'ended')
    at AudioPlayer.play (C:\Users\yusuf\Documents\programming projects\discordbots\emirates safety\node_modules\@discordjs\voice\dist\index.js:1126:18)
    at Object.run (C:\Users\yusuf\Documents\programming projects\discordbots\emirates safety\src\commands\play-safety.js:35:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Client.<anonymous> (C:\Users\yusuf\Documents\programming projects\discordbots\emirates safety\node_modules\commandkit\dist\index.js:643:7)
pliant bloom
#

you don't pass the audioresource to <AudioPlayer>.play(...) there

opal crest
pliant bloom
#

audioPlayer.play(resource)

#

you're not telling it what to play

potent tangleBOT
#

guide suggestion for @opal crest:
guide Library: Audio Player - Playing audio
read more

opal crest
# pliant bloom you're not telling it what to play

Right. I have corrected my code to

const { SlashCommandBuilder } = require("discord.js");
const {
    joinVoiceChannel,
    getVoiceConnection,
    createAudioPlayer,
    createAudioResource
} = require("@discordjs/voice");
const path = require("path");

module.exports = {
    data: new SlashCommandBuilder()
        .setName("play-safety")
        .setDescription("Plays the safety demo!")
        .addChannelOption(option => option.setName("vc").setDescription("the vc that you want the bot to join!")),

    /**
     * @param {Object} options
     * @param {import("discord.js").Interaction} options.interaction
     */
    run: async ({ interaction }) => {
        try {
            await interaction.deferReply()
            const channel = interaction.options.getChannel("vc")

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

            const audioPlayer = createAudioPlayer()

            const resource = createAudioResource(path.join(__dirname, 'audio.mp3'));

            

            const subscription = connection.subscribe(audioPlayer)

            audioPlayer.play(resource)
        } catch (error) {
            console.error("An error occurred:", error);
            interaction.followUp(
                "An error occurred while trying to play the audio. Please check the logs."
            );
        }
    },
};

now it is not returning an error but it is also not playing the audio

pliant bloom
opal crest
# pliant bloom time for the dependency report then
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.18.0
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: not found
- opusscript: not found

Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: not found
- @stablelib/xchacha20poly1305: not found
- @noble/ciphers: not found

FFmpeg
- version: 6.0-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
pliant bloom
#

well, there you go. missing both an opus and an encryption library

opal crest
#

ohhh

opal crest
#

hang on

pliant bloom
#

read the big information telling you what to do in the middle there. between the ******************

opal crest
#

right the ```
This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.

?
pliant bloom
#

that's the first line. neither in the middle nor between ****************************

opal crest
#

oh

#

heheh

pliant bloom
#

but with latest node versions you should be able to just tick the box to install those with the node installer on windows

opal crest
pliant bloom
#

yes (and tick the box to include those build tools)

opal crest
#

ohh

#

snm

opal crest
#

that was the onyl checkbox in the installer

#

it still dont work

#

🫤

pliant bloom
#

does npm install --global windows-build-tools work?

opal crest
#

returns that

#

who knew a discord bot for an airplane safety demo would be this difficult

#

😭

opal crest
pliant bloom
pliant bloom
#

yes, that's the correct box... it literally says "build tools" and "C++" there...

opal crest
#

hang on so now npm installing opus should work?

pliant bloom
#

yes

opal crest
#

u lied

#

jk

#

it dont work

pliant bloom
#

did you (re)start a new terminal after doing that? does it actually use the node/npm version you just installed?

opal crest
#

@pliant bloom u got any other ideas?