#archive-voice
30636 messages · Page 9 of 31
I want it instead of stopping working
He writes "I can't get in"
I was not able to read 😦
my bot has been acting up since the release of v13. Note that everything worked in pre-release. I created a new test bot peeling out enough to play an .mp3 file. In some cases it plays in others it throws seemingly odd errors. I would happily try again if someone can point me to a "this is it how it works" example. I'm following the one in the guide and I get the error using it. It will play a simple "hello.mp3" if I create a resource using just the file path. If I pass along a second parameter it will play if I set the inputType but it will fail if try to set inlineVolume. Tells me it can't find module node-opus and opuscript neither of which have I installed directly. @discordjs/opus is 0.5.3, voice is 0.5.5, discord.js is 13.0.1 Has anyone seen a) a similar error or b) a working example? Thanks.
Showing code will help us know about your condition
`
const getTestReply = function(msg) {
logger.debug('messageHandler.getTestReply');
if(!voiceChannel)
voiceChannel = msg.member.voice.channel;
if(!voiceConnection) {
const permissions = voiceChannel.permissionsFor(msg.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return msg.channel.send("I can't join your voice channel");
}
voiceConnection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});
}
if(!audioPlayer) {
audioPlayer = createAudioPlayer();
voiceSubscription = voiceConnection.subscribe(audioPlayer);
}
const cmd = 'test';
const soundFile = getSoundSource('hello');
//const resource = createAudioResource(soundFile, { inputType: StreamType.Arbitrary });
const resource = createAudioResource(soundFile, { inputType: StreamType.Arbitrary, inlineVolume: true });
// const args = getCommandArgs(msg, cmd);
// let volume = parseFloat(args);
// volume = isNaN(volume) ? 1.0 : volume;
// volume = isValueBetween(volume, 0.1, 1.0) ? volume : 1.0;
// resource.volume.setVolume(volume);
audioPlayer.play(resource);
return 'test';
}
`
i can reduce it some if I remove my logger, some of the checks and the function that gets the file path but they all work everywhere. This version would fail due to it having the inlineVolume setting even though I don't access it. The commented line above would work because it doesn't have that option.
I simplified the code a tiny bit if that is too much to look at but it won't change the way it works. I've essentially followed the example in the guide https://discordjs.guide/voice/audio-resources.html#creation but as I mentioned the inlineVolume parameter makes it fail. I see the comment says // Will use FFmpeg with volume control enabled perhaps it is the version of FFmpeg I have?
ffmpeg version 2021-05-12-git-175f675f7b-essentials_build-www.gyan.dev
Create a new file (name it as test.js)
Then add this code to there :
const { generateDependencyReport } = require('@discordjs/voice');
console.log(generateDependencyReport());
And then run this code with node test.js
Show me console.log
I have that as a built in admin command for my bot `--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.5.6
- prism-media: 1.3.1
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found
Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: not found
FFmpeg
- version: 4.4-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------`
Can you remove inputType when using inlinevolume and then check again. If it plays or not.
it won't work but I tried it... I think I found the error
`
//const resource = createAudioResource(soundFile);
//const resource = createAudioResource(soundFile, { inputType: StreamType.Arbitrary });
const resource = createAudioResource(soundFile, { inlineVolume: true });
//const resource = createAudioResource(soundFile, { inputType: StreamType.Arbitrary, inlineVolume: true });
Error: Error: Cannot find module 'D:\Repos\testBot\node_modules\@discordjs\opus\prebuild\node-v93-napi-v3-win32-x64-unknown-unknown\opus.node'
`
That's generated when I include either of the inlineVolume examples
Okay basically it is discordjs opus problem.
Uninstall discord js opus and install it again
Then check if D:\Repos\testBot\node_modules\@discordjs\opus\prebuild\node-v93-napi-v3-win32-x64-unknown-unknown\ folder exists or not
Excellent. I renamed node_modules and just reinstalled everything and this time the folder is present and it works! The old folder had something named this: node-v83-napi-v3-win32-x64-unknown-{libc_version}
how do I join or leave a voicechannel in v13
A rule to live by when in doubt reinstall node_modules... thanks for your help it is much appreciated.
you can read the guide: https://discordjs.guide/voice/voice-connections.html#voice-connections
npm ci exists
how to destroy an AudioPlayer? there's no destroy() function
you can use stop()
Is voice receive in a working state?
How can I get my bot into the stage channel every time the bot is ready?
new updates is very difficult
a release will be made in the next hour or so with working receive :D
oh perfect! thanks
released 😄
🔔 v0.6.0 released -- https://github.com/discordjs/voice/releases/tag/v0.6.0 🔔
npm install @discordjs/voice@^0.6.0
This release features support for audio receive - check the release and examples to see how to get started!
Looking at the example, it shouldn't be too bad to replace recording while someone is talking to playing an audio file right?
How do you mean?
As in, you want to play audio while recording a user at the same time?
Even without recording the user, checking when they're talking and then playing something during
ohh
yes that should be easy,
if you want to play something while someone is talking, you could use receiver.speaking.on('start/stop', userId => ...
so when they start speaking, you start playing your resource
and when they stop speaking, you stop playing your resource
ah that makes sense
Hmm
voiceConnection.receiver.speaking.on('stop', userId => console.log(`User ${userId} stopped speaking`));
isn't firing when stopping speaking
the started speaking is though

do you have video enabled at the same time or?
Nope
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
selfDeaf: false,
selfMute: false,
adapterCreator: channel.guild.voiceAdapterCreator,
});
connection.receiver.speaking.on('start', userId => console.log(`User ${userId} started speaking`));
connection.receiver.speaking.on('stop', userId => console.log(`User ${userId} stopped speaking`));
ah, it's end not stop
will update the release lol
aha all good tyty
start/stop probably made more sense but oh well
Is there a way to loop a resource? If I load outside of my join function I can't reuse it, but if I create it inside, it takes about a half second to load and play
oh I'm blind, I see playing opus streams on the docs now
@fallow linden is it a long resource?
very short - 8 seconds or so
i have a cool and good idea
oh actually nvm it might be harder than i thought lol
Essentially looking for it to start from the beginning every time the start function runs
my idea would have been to first read your stream into a buffer, and then make a generator over that buffer, and when it reaches the end of the buffer, it just starts from the beginning, and then you could just create a readable stream from the generator and it should be a looped audio stream then
i think that could still work
but dont have the time to test it
all good! I'll see if I can give that a go
good luck!
you know what, actually just moving into using opus it loads extremely quick now anyway, I can just define the resource in the start function and it's pretty much instant
ah nice ok, no worries then 😄
Why am I getting TypeError: adapterCreator is not a function?
Here's how I set up my connection:
const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
});```
Make sure you're using discord.js v13
yup, I've uninstalled and reinstalled it
Try to debug and check that message.guild.voiceAdapterCreator isn't actually undefined
it returned this:
methods => {
this.client.voice.adapters.set(this.id, methods);
return {
sendPayload: data => {
if (this.shard.status !== Status.READY) return false;
this.shard.send(data);
return true;
},
destroy: () => {
this.client.voice.adapters.delete(this.id);
},
};
}```
What message are you using in your connection?
wdym
adapterCreator: message.guild.voiceAdapterCreator
the one the user sends
shouldn't this be adapterCreator: channel.guild.voiceAdapterCreator
if a user sends a message in a guild, does it make a difference?
It probably shouldn't
or do you have to specify it's in a channel in a guild?
I was having the same issue like 2 hours ago but I forget exactly what I did
shouldn't it be adapterCreator: message.channel.guild.voiceAdapterCreator then
what do you have?
channelId: channel.id,
guildId: channel.guild.id,
selfDeaf: false,
selfMute: false,
adapterCreator: channel.guild.voiceAdapterCreator,
});```
But i'm passing in the channel the user is in
oh, I also need to fix the bot deafening itself for no reason
If you don't want it deafened yeah add selfDeaf false
👍
still get TypeError: adapterCreator is not a function
Error: No known SSRC for taget
can you show your whole script
Hmm, I just tried your connection and it worked for me, using a message
could it be an intent issue?
that doesn't make sense though
You didn’t provide an adapter for the joinVoiceChannel function
try adding Intents.FLAGS.GUILD_VOICE_STATES
already added
how do I do that?
adapterCreator: <Guild>.voiceAdapterCreator
is this not the guild? adapterCreator: message.channel.guild.voiceAdapterCreator
yeah you have that, I tried the exact same thing and it worked
this is my client and intents const Discord = require('discord.js'); const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_VOICE_STATES] });
could it be a command handler issue?
yeah, I have those
should I send my main.js file?
sure, i can give it a go
I think it's something to do with your versions
using your main and play files it still worked
{
"name": "omex",
"version": "1.0.0",
"engines": {
"node": "16.6.x"
},
"description": "Discord bot",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "FallenHero",
"license": "ISC",
"dependencies": {
"@discordjs/opus": "^0.5.3",
"@discordjs/voice": "^0.5.5",
"discord.js": "^13.0.0",
"ffmpeg-static": "^4.4.0",
"yt-search": "^2.10.0",
"ytdl-core": "^4.9.1"
}
}
wait one last thing
did you pick any scopes with oauth2?
nope
should I pick bot?
I did bot, builds upload, and builds read
what about rpc.voice.write?
I didn't add it, but toss it in there for now
it says please enter a redirect uri
I think it should be url
for a bot the only ones u really need are bot and now for slash-commands application.commands
still get TypeError: adapterCreator is not a function
try updating to 0.6, but I don't think it'll change it
update @discordjs/voice to 0.6 and djs to 13.0.1
everythings working for me with your code
see if that resolves
how do you install a specific version?
is it npm install discord.js 13.0.1?
I think it should be npm install discord.js@13.0.1
and npm install discord.js/voice@0.6.0, right?
wait, it's not this
should I get npm install @discordjs/voice libsodium-wrappers?
nope, same error
oh well
my node version isn't an issue, right?
16.6.1
That should be fine
Are you able to run the music bot example in the repo @golden path?
can you link it?
it should just be the examples folder on the repo homepage
should be in pinned messages
yup, I see it
joinChannel is not a function
I defined it with const {joinChannel} = require('@discordjs/voice')
It’s joinVoiceChannel
I don’t think the example nor the guide uses joinChannel
my bad, I got this error again though TypeError: adapterCreator is not a function
I've tried reinstalling numerous times and that hasn't changed anything
You should really read the guide. I believe the voice connections section covers this
yeah, I used the code from it
Show ur code then
I don’t think I’m in that guild
You have another joinVoiceChannel on line 54 missing the adapter
can i join the bot in the stage channel with djs v12 .d i dont understand v13 , really
No
oh so how can i join my bot with v13
Use the voice package (guide in pins)
sorry, I copy and pasted the message id instead of the link
i read guide but I couldn't use it properly
Do you still have ur code?
i only have a blank v13 code
how can i use this codes
https://discordjs.guide/voice/voice-connections.html#creation
can you please tell me
I mean, it’s pretty much written out for you
You call the joinVC function with the shown parameters
should I just remove line 54?
I’d actually remove the first joinVC
yeah
what do I define createAudioResource with?
ReferenceError: createAudioResource is not defined
wait, nvm. I got it
Which one of these should I use? Install sodium, libsodium-wrappers, or tweetnacl.
sodium it is
sodium is recommended
Any will work tho
do I need to add anything to my file?
No, dependencies are auto-detected
I get the same error again even after installing sodium.
should I throw something in package.json?
Run npm ls sodium
I assumed you installed it using the npm i command
Is it not in there already?
I used npm install node-gyp -g
How would I go about playing local audio files in a voice channel and then automatically playing the next one after its finished?
That’s node-gyp tho
I'm also running my bot off a server, not from my terminal
npm install sodium gave an error
You can’t ssh into the server?
secure shell?
Yea
I just use the command prompt on heroku
Oh, ur using heroku
is that an issue?
What error does it give?
Heroku doesn’t have libtool installed?
should I use heroku create --buildpack https://github.com/jedisct1/libsodium.git?
I could install libtool then try sodium
I was gonna say, seems like heroku lets you install libtool via Stacks
how?
It’s actually supposed to alr be installed
Which heroku stack are you using?
heroku-16, 18, or 20
Ubuntu 20.04
Should be in the 2.4.6-14 version of that stack then
Only available during build time tho
any idea how to fix that?
wait, how do I check which stack I'm using? I just looked at the default one on the website
Can I not just upgrade to a different stack?
https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack
I think the install has to happen when you deploy it, can’t install it via Heroku cli
I only created it like less than a month ago
before that, I was running off a different server
I'd assume it'd be the most recent version
Normally, you’d have a separate server or use ur computer for development, then once ready, you’d push it to a GitHub and Heroku would pull, build, and run
yeah, that's what I currently do
wait, a separate server for development?
I should probably do that 😅
Well, Heroku isn’t meant to be used for development/testing
true
I can figure that out later
Guess ur gonna have to manually add sodium to the package.json
yeah, I did that for discord.js/opus and voice
No
got it
That looks like a different package
Installation should work fine, seems like Heroku has everything it needs
I just installed libsodium
wait, that didn't do anything
I got this trying to install libtool
Someone told me my intents aren't being used. How do I do that?
const { Client, Intents } = require('discord.js');
const { joinVoiceChannel } = require('@discordjs/voice');
const Discord = require('discord.js');
const myIntents = new Intents();
myIntents.add(Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGES);
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.once('ready', () => {
console.log('Online');
});
client.on("voiceStateUpdate", (oldMember, newMember) => {
console.log(newMember);
if(oldState.speaking !== newState.speaking) {
console.log("Spoke");
}
const channel = client.channels.cache.get(newMember.channelID);
if (newMember.id === "277484746265722881") {
if (!channel) return console.error("The channel does not exist.");
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
}
});
😳
if you didn't notice -- ```const myIntents = new Intents();
myIntents.add(Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGES);
you want const client = new Client({ intents: myIntents });
You need libsodium-wrappers
what's the command for that?
npm i libsodium-wrappers
This code is spamming my console. Does anyone know why?
console.log(newMember.id);
const channel = client.channels.cache.get(newMember.channelId);
console.log(channel.id);
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
})
if (newMember.id === "277484746265722881") {
}
if (!channel) return console.error("The channel does not exist.");
});```
```Bot Online
main.js:9
277484746265722881
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668
main.js:15
873763407487189003
main.js:13
836998244147396668```
Because you have a lot of voice state updates? https://discord.js.org/#/docs/main/main/class/Client?scrollTo=e-voiceStateUpdate
"Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes."
✅
When I disconnect from a voicechannel and my bot can't find my channel.id it crashes, how do I add a fail-safe?
const channel = client.channels.cache.get(newMember.channelId);
if (!channel) {
console.error("The channel does not exist.");
client.destroy();
}
if (newMember.id === "277484746265722881") {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
})
if (!channel.id) console.error("The channel does not exist.");
console.log(channel.id);
}
});```
``` channelId: channel.id,
^
TypeError: Cannot read property 'id' of undefined```
I used to have
// console.error(e);
// if (!channel) return console.error("The channel does not exist.");
// });```
but that doesn't work here
Why are you going through channels cache only to get channel of newState.
Use this simple : const channel = newMember.member.voice.channel
Add a return to fix that issue after client.destroy()
if (!channel) {
console.error("The channel does not exist.");
client.destroy();
return
}
Thank you!
It took me awhile too to get used to DJS passing around fully-linked objects like that. It's pretty efficient in some sense...definitely developer friendly.
it looks like client.destroy turns the bot off all together, is there a way to just disconnect it from the voicechannel it's in?
Yep. voiceConnection.destroy() @fallow locust Obviously you need to get a reference to the existing voice connection from somewhere 🤡
For that use getVoiceConnection from discordjs/voice module
https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#access
Sorry for the ping
I'm guessing I'm doing it wrong
connection.destroy();```
I did that but the console keeps saying myVoiceChannel is not defined. Sorry I'm bad at this I just started with bots 😕
Change myVoiceChannel to oldMember
That disconnected it correctly but the bot crashes after in the console
^
TypeError: Cannot read property 'destroy' of undefined```
You need to make sure that bot is also connected to that guild or not
Do something like :
if(connection) connection.destroy()
It works!
??? How could it disconnect from the channel but also not be defined?
Thank you guys so much
hello, i want to know is @discordjs/voice better than @discordjs/opus now?
Those are not the same thing
oh what are those then i misunderstood i thought they're same
Voice is for managing voice-related aspects of Discord.js basically. Opus is just bindings to the system's copy of libopus.
see pins,
@discordjs/opus is a opus encoding library
While @discordjs/voice is voice module for bot to connect to vc in discord and make it emit audio sent by you.
@carmine timber Why do you need to use PCM with inline volume?
alright got it ty
Because Opus doesn't support Volume Transformer ( That is used to control volume at any time ) . PCM does support changing volume at any point of time
Thanks. Kinda weird though, I wonder why that is.
hi, i have used the example music bot in pins and rewote it exactly into simple js... fixed few errors.. now it shows track enqueued and i see green circle around the bot in vc but i cant hear music...i have checked the volume... no errors also showing. pls help
It would help if you showed the relevant code in question and please don't be too picky. The more code, the easier it is.
ok srry
heres the code
https://pastebin.pl/view/bf65b84c
Can you show me your processQueue? Or whatever you called the function handling the queue.
If the green circle is lighting up, something is coming over...hmm
yeah i have a subscription.js
https://pastebin.pl/view/8a252ca3
heres the code
process queue is declared here
hey guys how do I undeafen my bot? it's on self-deafen
@fallow locust In joinVoiceChannel pass selfDeaf: false
@summer crow I didn't know Pablo was only working on chuck e cheese.
thanks, ur the best
😎
what?
Belooga
eugene- i meant
This also looks fine to me.
Not a place to talk here go to #archive-offtopic
sorry.
Is there a way to make the bot detect when someone speaks?
As of 0.6.0 yes, see latest pinned message, example is in release notes
What you have to do next with the PR ??
I found a bug yesterday that needs to be fixed
Can you tell me ??
Oh sorry it's not your PR, it's for receive
😦
Your pr will come soon enough
It's just that receive takes priority since users can't add that themselves
Okay
I think you can easily set the volume of an Opus decoder...but not encoder. Prism hasn't built it in but it's a simple addition. 🤔
Hello how do i make my bot automatically Server mute itself
the old method im using is not working anymore
Documentation suggestion from @late osprey:
VoiceState#setMute()
Mutes/unmutes the member of this voice state.
guild.me.setMute(true) should do it.
thanks
guild.me.voice.setMute(true)
@zenith tiger Sorry
no problem
Error: aborted with resource what's this err, please help,
It was working fine before but suddenly it disconnected and thrown this error,
https://github.com/fent/node-ytdl-core/issues/902
May be this issue
FIX :
Confirmed, setting ytdl-core highWatermark option to 32MiB on Node.js v16 (16.5.0) fixes the problem, so the workarounds are use Node v14.x or play with the highWatermark settings, not sure if this will apply to everyone
I had it occur even with it set higher. I'd recommend use Node 14 if you insist on using ytdl-core.
But you can't switch to Node 14 if you are on djs see #769862166131245066
Ahhh fack you are right
Voice itself soon going for v16 as well because of adding in AbortController
I'm trying to make a thing that if a user isn't in a voice channel, it reutrns an error.
Here's the code i'm with
if(!interaction.member.voice.channel) return interaction.reply({ content: `Vous devez être dans un salon vocal pour pouvoir utiliser cette commande`, ephemeral: true });
But the thing it's that it will always return the error even if i'm in a voice channel
Maybe change this code to :
if(!interaction.member.voice?.channel) return interaction.reply({ content: `Vous devez être dans un salon vocal pour pouvoir utiliser cette commande`, ephemeral: true });
Still don't
What type of interaction is this ???
Discord voice channels activites (poker, youtube together, chess etc)
I mean to say, slash or button or select menu ????
okay , thanks
oh slash commands
my bad
Add this line before this code -- console.log(interaction.member.voice.channel)
And then tell me what you get ??
the first is when i'm in a voice channel is when i'm in a vc and second one no
So simple fix :
let channel = interaction.member.voice.channel
if(!channel) return interaction.reply({ content: `Vous devez être dans un salon vocal pour pouvoir utiliser cette commande`, ephemeral: true });
Still...
Add one more line before if condition console.log(interaction.isCommand())
Then show me console log
it logs true
@cerulean dock Change this console log to console.log(interaction.member.id === client.user.id)
it logs false
What was the point of that? bots can’t execute interactions
Just checking if the interaction.member class is not of bot itself.
Solve this problem then
how can i set volume?
Do you have the guild voice states intent enabled?
Resource.volume.setVolume(…)
@icy maple What guild voice states intent ???
whats default?
The intent to receive voice state updates
see replied message of that
He gets interaction.member.voice.channel
How to make the bot join a voice channel where the member is?
But it’s not updating
Hence, he’s not receiving voice state updates
Yeah
Use joinVoiceChannel function provided in the voice package (guide in pins)
his interaction.member.voice.channel is not undefined but the return command is being executed. Can you explain ???
how can i change volume after
^^
setTimeout(() => { player.pause(); }, 5_000)
setTimeout(() => { player.unpause(); }, 15_000)
setTimeout(() => {
resource.volume.setVolume(0.75)
}, 20_000);```
```js
resource.volume.setVolume(0.75)
^
TypeError: Cannot read property 'setVolume' of undefined```
You need to pass inLineVolume as true when creating resource
@cerulean dock Log !channel and channel before the if statement, and smth inside of the if statement before the return (e.g. "member not in channel")
i'm going to do that, just i finish a game
Hello my bot is not playing ytdl streams
it just skips the entire video
It is your queue problem not voice module problem
but it plays other streams without problem
for instance, a stream parsed from an attachment
If that's the case, create your issues in github of ytdl-core not here. Here we give help of voice module not ytdl help
channel and !channel
i dont think its ytdl problem because i can still convert its stream into file
Then show me the code
Show me where you have defined client in main file
@icy maple It was the intents. Thank you both of you tho @carmine timber
Okay 👍
if you want to play the audio in 2 channels on 2 servers you have to do sharding?
nvm it suddenly worked
No need for that
What's the event name for when an audio finishes playing? Something like this? .on("finish", () => {}I can't find anything on docs
The audio player goes back to idle
Thank you
@carmine timber
Thanks for your help the other day. I finally figured out what was happening. Turns out ffmpeg-static silently segfaulted on my machine. Using the system ffmpeg solved the issue. I used the -report option on the ffmpeg instance to generate a log file in which was the actual ffmpeg command that gets executed. Trying this command in a terminal resulted in a segfault.
No problem man.
How to make bot join the Stage
let resource = createAudioResource(ytdl(...));
player.play(resource);
```Bot ain't outputting any audio. I got `GUILD_VOICE_STATES` intent but nada.
connection.subscribe(player)
Ahh. Thanks
👍
help me piz
I installed all 3 encriptiong thingy but I still get the same error
Check with npm ls sodium
Which same error ??
throw new Error(`Cannot play audio as no valid encryption package is installed.
^
Error: Cannot play audio as no valid encryption package is installed.
install sodium or libsodium-wrappers
Type npm list sodium
@fervent estuary He said he has all 3
doesnt look like so according to the error
I also gt this error
npm ERR! path /home/container/node_modules/sodium
npm ERR! command failed
npm ERR! command sh -c node install.js --preinstall
npm ERR! /bin/sh: 1: make: not found
npm ERR! /home/container/node_modules/sodium/install.js:293
npm ERR! throw new Error(cmdLine + ' exited with code ' + code);
npm ERR! ^
npm ERR!
npm ERR! Error: make libsodium exited with code 127
npm ERR! at ChildProcess.<anonymous> (/home/container/node_modules/sodium/install.js:293:19)
npm ERR! at ChildProcess.emit (node:events:394:28)
npm ERR! at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! A complete log of this run can be found in:
npm ERR! /home/container/.npm/_logs/2021-08-11T12_00_58_346Z-debug.log```
Try typing npm list libsodium-wrappers
I am on a pannel so this happens
Show me package.json
"@discordjs/opus": "^0.5.3",
"@discordjs/voice": "^0.6.0",
"buttube": "^0.4.1",
"discord.js": "^13.0.1",
"ffmpeg": "^0.0.4",
"ffmpeg-static": "^4.4.0",
"opusscript": "^0.0.8",
"ytdl-core": "^4.9.1"
}```
That is a very odd dependency conflict
Try adding "libsodium-wrappers": "^0.7.9",
and restarting node again
buttube is conflicting with voice for some reason
bro it is my package
So ur saying that the package is dependent on itself?
tysm
Bc you have buttube in the dependencies
Leave it, he has some 3rd party stuffs
I am the creator of that package
What’s the name in the package.json?
it is bcs distube requires @discordjs/voice v5 and I installed v6
buttube
You can’t name the project the same thing as one of its dependencies
channel.join is not a function at Object.execute (C:\Users\96655\Desktop\v13+\ser\command\play.js:128:55) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) C:\Users\96655\Desktop\v13+\ser\command\play.js:134 await channel.leave() ; TypeError: channel.leave is not a function
const { channel } = member.voice.channel; queueConstruct.connection = await channel.join() await queueConstruct.connection.voice.setSelfDeaf(true); play(queueConstruct.songs[0], message); } catch (error) { console.error(error) message.client.queue.delete(message.guild.id); await channel.leave();
You have to use the new voice package to join vc (guide in pins)
It has been downloaded but is there a modification because there is an error s\96655\Desktop\v13+\ser\command\play.js:16
const { channel } = member.voice.channel ^ReferenceError: member is not defined
It appears that member isn’t defined
Kinda weird since you didn’t get that error previously. Did you accidentally delete its definition?
No, I did not delete it, but I did not find any modifications to a member on the site
Can you show me play.js from starting till line 17
Really I'm trying to update the code because after the update the bot crashed completely and I don't know why
how to get a readable stream from the voiceconnection class in v13?
i used to that in v12 like you see in the screenshot.
The most pin tag has the link with an example
Is there any one have suggestion for large bot's queue system?
apparently in v13 bots can join stages??
How do i make it join bc making it join like a regular vc doesnt work for me
i also installed the voice package
According to the discord.js/voice guide (https://discordjs.guide/voice/), you can establish a connection via the joinVoiceChannel function
damn this is a lot different
This is on creation of voice connection
never seen it and no idea what it is
It’s just internal stuff
Guild#voiceAdapterCreator
The voice state adapter for this guild that can be used with @discordjs/voice to play audio in voice and stage channels.
do i leave it as is? or do i fill it with something?
Leave it
I don't know if this is related to the new voice package on Discord but when I try to get the voice channel from a user, I get this: https://cdn.discordapp.com/attachments/849159665051893781/875014140295544832/unknown.png
You need the guild voice states intent
Voice states aren’t related to the voice package
The persence Intent? I've got the Server Members Intent and it has always worked well
U need GUILD_VOICE_STATES intent
Oh okay okay now I understand
is there any better way to seek in audio without using a new prism media ffmpeg stream because at the moment i spin up 2 different ffmpeg processes for one connection this is not efficient i think
Please ping me if you have a response
There is no other way to seek the audio other than FFMPEG as far as I know.
But why do you have 2 different ffmpeg processes for one connection
one that discordjs's and one for my seeking
Which discordjs's one ??
idk probly for encoding to opus
i didnt look to discord.js/voice codes
If you are using inLineVolume with seek better to convert seeking FFMPEG to transcode for PCM, it is a better solution
nope im not using inline volume
So can you tell me FFMPEG args ??
let ffmpegArgs = ["-ss", seek.toString(), "-i", this.currentAudioPath, "-f", "wav"];
this.prismFfmpegStream = new prism.FFmpeg({ args: ffmpegArgs });
this.audioResource = createAudioResource(this.prismFfmpegStream);
this.audioPlayer.play(this.audioResource);
These FFMPEG args will always force 2 ffmpeg processes
how i can fix that
by changing the format ?
to opus or something?
i tried both wav and opus, wav worked faster idk why
const FFMPEG_OPUS_ARGUMENTS = [
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
];
const ffmpeg_instance = new FFmpeg({
args: ["-ss", seek.toString(), "-i", this.currentAudioPath, ...FFMPEG_OPUS_ARGUMENTS]
});
Use this ^^
thanks 🙂
still two tho
Can you console.log(audioResource) that is created ??
I just want edges from there
ffmpeg ogg and ogg/opus demuxer
Yes That should not be the case.
Wait
why is this guy stuck for 15 minutes right over here????
[..................] \ idealTree:new code: sill idealTree buildDeps```
Which module installation ??
npm i @discordjs/voice```
Ctrl + c and run npm i @discordjs/voice@latest
worked thank u
No problem
how can i know audio play is end?
How to stop the current audio without destroying anything else? .stop() stops the audio and destroys. I'm aiming to just skip the current audio
how can i join the vc with eval command
how to join voice on v13?
Figured. Just subscribe to a new player. However the bot just suddenly stops playing audio after some time eventhough the track hasn't ended. Anyone else?
Unsubscribe to the subscription https://discordjs.guide/voice/voice-connections.html#playing-audio
Thank you
play on stage ?
Hello, with @discordjs/voice, can I disconnect my bot with connection.disconnect() ?
Does anyone know if @discordjs/opus is supported on ARM Mac's?
Does anyone know when voice receiving will be supported or if it currently is? Will it be released in the 13.1 update? Will there be an announcement when it releases?
Support was added yesterday
See pins for example
Am I doing anything wrong?```js
let player = createAudioPlayer();
player.play(createAudioResource(ytdl(url, {filter: "audioonly"}), {config.musicSettings}));
getVoiceConnection(message.guild.id).subscribe(player);
player.on("error", () => {...})
Well it doesn't crash. It keeps going to error event. The song plays but then midway, it triggers the error event
I'm sorta having a similar problem, where like I have a few songs queued and in the idle event it skips to the next song
Thank goodness for that. Thought it was just me. Guess it could be a library issue
Oh never mind
How do i make my bot set itself as speaker?
nevermind
Hi, just a quick question: Is it possible to change the volume of a playing sound from the PlayerSubscription? I want to change the volume via a different command from a different file but I don't know how to access the resource volume from there.
resource.playStream.once('error', onStreamError);
^
TypeError: Cannot read property 'once' of undefined
Why i get this error when i will start playing music?
because .once doesn't exist for .playStream
you want to put the error listener on player.on if you want to listen for an error on your music
But i get this error from my node_modules i don't use this
U got node 16 installed?
Yes
how do i get the bot to play an mp3 stream from a custom link?
ytdl wont work in this case sadly
Oh
Is it possible to change "selfDeaf" or "selfMute" without creating a new VoiceConnection?
is it possible to get the player from a specific connection via the
getVoiceConnection(myVoiceChannel.guild.id);
or do I need to create a new one each time I play a new song?
Well, I think you can do this:
const connection = getVoiceConnection(myVoiceChannel.guild.id);
const player = connection.state.subscription.player;
But you need to verify if the connection has a subscription
I think I found it, if you do like
playerOG.on(AudioPlayerStatus.Playing, (info) => {
console.log(info);
console.log('The audio player has started playing!');
// message.channel.send('Now playing');
});
it returns within info.resource.audioPlayer doing some test rn to find out if in idle I can just access it and add the resource
Nice. Ty
Any docs to learn how to begin with this new library?
can somebody help me on this?
Use something like this:
channel.join().then(connection => {
connection.play(YOUR_URL);
}
im on v13
and if i try to change it up to something similar, i get this error
we cannot help with just the debug, show code. It looks like you are legit just putting a string inside the method
lemme put it in a bin and ill show u
https://sourceb.in/VB6toVCKrd
here is the code that I am using
Djipen wanted me to do something along the lines of connection.play('url') but that wouldnt work for this. I used a youtube url as an example but the actual link will not be from youtube
channel.join().then(connection => {
Issue: So basically i'm using this in a interval. So I join the vc, user the command that has this code, but when I leave the voice channel, the bot will send a error saying that the bot can not join the vc.
Ping me with the answer please
Hey are you available?
Yes sure
Either wrong channel or wrong djs-version
You told me to create player in main file and play the audio resource on ready event
Yes
But the thing is, my code is not single file
You can't directly play youtube url like that
Everything is in different directory
Do you have handlers for commands, events ??
Yep
Keeping everything in 1 file is mess
Are you in js or ts??
Using V12
Js
This channel is for v13 not for v12,
ask that question #archive-djs-v12-voice-deprecated
Ah. Thank you.
Sorry about this
Then I think you can attach player to client class in main file like :
client.player = createAudioPlayer()
And then in ready event just do :
client.player.play(resource)
In main command file, you can do :
connection.subscribe(client.player)
Can you come to dm I'll send you my current code because it kinda feels similar to my implementation
Sure
Is there a alternative function for VC.join for discord.js v13?
My bot connects to my voice channel when I do and disconnects when I do, but when it's disconnected it stays disconnected. I want to make it so my bot comes back to the voice channel if it's disconnected and I'm still in it. How would I do that?
const channel = client.channels.cache.get(newMember.channelId);
console.log(oldMember.id);
if (oldMember.id === "277484746265722881") {
if (!channel) {
console.error("The channel does not exist.");
const connection = getVoiceConnection(oldMember.guild.id);
if(connection) connection.destroy();
return
}
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false,
})
}
});```
I'm assuming I'd have to add some sort of if statement to jump fromif (!channel) { to const connection = joinVoiceChannel({ but I'm not sure how to do that.
Don't make the same mistake as me check the examples for music bot
Any idea?
Not in cache also
It's only happening with my bot and my other bots are working fine
what are you getting at here?
Even my another bot which is running on same code runs fine
you're just posting a bunch of out-of-context eval screenshots
The voice state is null
did you enable the voice state intent?
Even I'm in vc
Yes I have, it only happening on some servers
Try to run m!ev console.log(msg.guild.voiceStates.cache)
Ok
@carmine timber
How it is null ,then ??
Well it is
Show me joining command
Wait
let memberVoice = msg.member.voice.channel;
if (!memberVoice) return this.client.send(msg.channel.id, {
embed: {
color: this.client.util.color.error,
description: `${this.client.util.emoji.error} | You must be in a voice channel to use this command!`
}
});
does anyone know why is -af "volume=0.5" argument is not working while working with prism ffmpeg
while im trying directly in console it works but not in prism
Maybe remove the speech marks
tried that too nothing changed
[
'-i',
'C:\\Users\\Armagan\\Desktop\\v13-music\\tmp\\media\\817408899904438282\\1628750072049.mp3',
'-af',
'"volume=0.50"',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2'
]
arguments I giving
instantly goes to idle state
Mention me if someone wants to help me
Show me playing code
I think you are doing something wrong.
async playFromFile(filePath, seek = 0, volume = this.lastVolume) {
this.lastAudioPath = filePath;
this.audioPlayer.pause(true);
try { this.prismFfmpegStream.destroy() } catch { };
let ffmpegArgs = ["-i", filePath, "-b:a", this.bitrate.toString()];
if (seek) ffmpegArgs.unshift("-ss", seek.toFixed(2));
if (volume != 1) ffmpegArgs.push("-af", `"volume=${volume.toFixed(2)}"`);
ffmpegArgs.push(...FFMPEG_OPUS_ARGUMENTS);
this.lastSeek = seek;
this.prismFfmpegStream = new prism.FFmpeg({ args: ffmpegArgs });
console.log(ffmpegArgs);
this.audioResource = createAudioResource(this.prismFfmpegStream, {
inputType: StreamType.OggOpus,
});
this.audioPlayer.play(this.audioResource);
}
``` ^^
does something wrong?
Add some more lines before this code :
const path = require('path')
async playFromFile(filePath, seek = 0, volume = this.lastVolume) {
let actual_path = path.resolve(filePath)
this.lastAudioPath = actual_path;
this.audioPlayer.pause(true);
try { this.prismFfmpegStream.destroy() } catch { };
let ffmpegArgs = ["-i", actual_path, "-b:a", this.bitrate.toString()];
if (seek) ffmpegArgs.unshift("-ss", seek.toFixed(0));
if (volume != 1) ffmpegArgs.push("-af", `"volume=${volume.toFixed(2)}"`);
ffmpegArgs.push(...FFMPEG_OPUS_ARGUMENTS);
this.lastSeek = seek;
this.prismFfmpegStream = new prism.FFmpeg({ args: ffmpegArgs });
console.log(ffmpegArgs);
this.audioResource = createAudioResource(this.prismFfmpegStream, {
inputType: StreamType.OggOpus,
});
this.audioPlayer.play(this.audioResource);
}
path is already resolved
async playFromFile(filePath, seek = 0, volume = this.lastVolume) {
this.lastAudioPath = path.resolve(filePath);
this.audioPlayer.pause(true);
try { this.prismFfmpegStream.destroy() } catch { };
let ffmpegArgs = ["-i", this.lastAudioPath, "-b:a", this.bitrate.toString()];
if (seek) ffmpegArgs.unshift("-ss", seek.toFixed(2));
if (volume != 1) ffmpegArgs.push("-af", `"volume=${volume.toFixed(2)}"`);
ffmpegArgs.push(...FFMPEG_OPUS_ARGUMENTS);
this.lastSeek = seek;
this.prismFfmpegStream = new prism.FFmpeg({ args: ffmpegArgs });
this.audioResource = createAudioResource(this.prismFfmpegStream, {
inputType: StreamType.OggOpus,
});
this.audioPlayer.play(this.audioResource);
}
Ok then do this :
async playFromFile(filePath, seek = 0, volume = this.lastVolume) {
this.lastAudioPath = filePath;
this.audioPlayer.pause(true);
try { this.prismFfmpegStream.destroy() } catch { };
let ffmpegArgs = ["-i", filePath];
if (seek) ffmpegArgs.unshift("-ss", seek.toFixed(2));
if (volume != 1) ffmpegArgs.push("-af", `"volume=${volume.toFixed(2)}"`);
ffmpegArgs.push(...FFMPEG_OPUS_ARGUMENTS);
this.lastSeek = seek;
this.prismFfmpegStream = new prism.FFmpeg({ args: ffmpegArgs });
console.log(ffmpegArgs);
this.audioResource = createAudioResource(this.prismFfmpegStream, {
inputType: StreamType.OggOpus,
});
this.audioPlayer.play(this.audioResource);
}
Testing purpose only removing bitrate
ok wait
Can you show me Opus arguments ??
const FFMPEG_OPUS_ARGUMENTS = [
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
];
``` the arguments you sent before
same not working
Okay
Create a new file (name it as test.js) and then add this :
const { generateDependencyReport } = require('@discordjs/voice');
console.log(generateDependencyReport());
And then do node test.js
ok
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.5.6
- prism-media: 1.3.2
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found
Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: not found
FFmpeg
- version: 2021-07-04-git-301d275301-full_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
Can you wait for this PR to finish ??
hmm
@vocal valley Please review fast, it would be lot easy to just tell someone to use createFFMPEGResource function
sure i can wait for that
I'm reviewing at the speed I can
I have a lot of other commitments besides discord.js
uh, no problem
and it's not a critical PR, the functionality can still be achieved outside the library
But sometimes it is very difficult for someone to setup FFMPEG args
You can do one thing.
Clone this repository (https://github.com/killer069/voice)
And then compile it with tsc
And then replace dist folder with node_modules/@discordjs/voice/dist folder
Actually, I don't need to do this. After all, the arguments used are the same, the volume will probably not work again.
@carmine timber Am I right?
const resource = createAudioResource('/home/user/voice/track.mp3');
so can i put ytdl-core stuff in the path so it plays audio from youtube video?
Yes, follow the examples around the guide/examples.
When you wanna seek something currently playing (via manual FFmpeg), do you just...recreate the stream with the seek args and drop it into .play?
Yes
Thanks
That works I have tested that
you are tested with volume right?
Yes I used all these args with new filename and played it and worked almost fine
huh
odd
i just updated my ffmpeg and still same sadge
It is your path problem, just do path resolve once again
tried nothing changed
tried pcm stream too
Does it work with a remote resource? Not some local file? If so it's your pathing or resolving.
nope directly just plays blank audio
Run new CMD and do run this :
ffmpeg -i "C:\\Users\\Armagan\\Desktop\\v13-music\\tmp\\media\\817408899904438282\\1628750072049.mp3" -af "volume=0.50" -acodec libopus -f opus -ar 48000 -ac 2 test.opus
that works
yep i alredy tired that
not working only when using prism
tried piping on console too that works too
Can you log ffmpeg instance for me
Just before creating audio resource
huh ok
What did you get ??
btw plays without volume argument
with volume arguemnt evrything breaks
im using that
-af jsut a shortcut for filters:a
Can I kick and move users without having the voice module installed?
Alr thanks
Hey, can someone help me pls ?
Error :
Error: TypeError: channel.join is not a function
code :
const channel = message.member.voice.channel;
try {
const connection = await channel.join()
queueConstruct.connection = connection;
play(queueConstruct.songs[0]);
} catch (error) {
console.error(`Je ne peux pas rejoindre le salon vocal.\nError: ${error}`)
bot.queue.delete(message.guild.id)
// await channel.leave()
return message.channel.send(`Je ne peux pas rejoindre le salon vocal.\nError: ${error}`)
}
I already install @discordjs/voice@^0.6.0
Ping me
Thx
Hey can someone tell me why i have this error ?
Error :
ERROR: FFMPEG is not installed. Install with "npm install ffmpeg-static" or download it here: https://ffmpeg.org/download.html.
I'm on Windows ans I already npm install ffmpeg-static
Download ffmpeg from that site in a separate folder and then add that folder location to environment variables
I looked on youtube and it said put ffmpeg.exe in its bot folder
u need to add it to path
Ok i try
The folder or juste ffmpeg.exe ?
just install it with npm install ffmpeg-static or look at a tutorial on how u can install it on ur system. Also u can use smth like chocolatey
ERROR: FFMPEG is not installed. Install with "npm install ffmpeg-static" or download it here: https://ffmpeg.org/download.html.
i don't understand....
npm install ffmpeg-static
up to date, audited 193 packages in 2s
18 packages are looking for funding
run npm fund for details
found 0 vulnerabilities
audio player keeps going to autopaused.
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});
Rename node_modules to something else and then do npm i
Broke my bot. Thank you. 
and I've got no sound.
I have declared NoSubscriberBehaviour in the constraint for discordjs/voice
Welcome. No problem 🙂
that was my bad XD I didn't declare NoSubscriberBehaviour
Ok XD
const { createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: guild,
adapterCreator: channel.guild.voiceAdapterCreator,
})
//create Audio Player and Audio Resource
const player = createAudioPlayer({
behaviors: {noSubscriber: NoSubscriberBehavior.Play}
});
connection.subscribe(player)
const resource = createAudioResource(ytdl(youtubeLink, {filter: 'audioonly'}));
player.play(resource)
interaction.reply({content: "Playback Started, run `/yt-stop` to stop playback." })
player.on('stateChange', (oldState, newState) => {
console.log(`Audio player transitioned from ${oldState.status} to ${newState.status}`);
if(player.state.status == 'idle'){
connection.destroy()
interaction.reply("Playback has ended.")
return;
}
});
}
else {
interaction.reply("You have not provided a valid YouTube link. Try Again.")
}
}
}```
should probably make this a thread.
I understand this. I stated how another user wanted me to do this but I knew it wouldn’t work. I want to know how I can play urls
Search ytdl-core for playing audio from youtube
I won’t be playing YouTube urls. Was using that one as an example
Okay
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
const resource = createAudioResource('/home/user/voice/track.mp3');
player.play(resource);
connection.subscribe(player);```
so is this how to play audio and join voice channel
Player was created or not ??
If yes, then code is right
yes the player was created
Then code is correct
any ideas on what i can do?
What do you want to play ??
im just playing a link that broadcasts a live audio stream
or i want to at least
You can send that directly to createAudioReosource
how exactly?'
most bots that uses other sources links actually just takes the info from spotify then looks up on youtube for the audio source
again im not using youtube
what source?
its just a audio broadcast from a radio station
is it.mp3, ogg, what format what source?
pretty sure its mp3
Just do createAudioResource(url)
^
would i replace the createAudioPlayer with that instead? Like I mean where u define player.
i see its a lil different
Why would you replace a AudioPlayer and with what ??
ik i realized just now
i am looking at the discord.js guide site and seeing why i shouldnt do that
assuming I got it a little bit correct, is it supposed to look somewhat like this?
const resource = createAudioResource(url('url here'))
player.play(resource)```
@carmine timber
No just paste the url in createAudioResource(<Url here>)
oh ok
doesnt work exactly. Shows that icon around the bot is green but isnt outputting any actual audio
nevermind
Worked ??
oh yea


Any guides to begin with this library?
Okay thanks
how am i able to set the mode for audio output in AudioReceiveStream
how do you get a user's voice channel?
anyone have problem with joining the channel will reset a shard ?
Im trying to make the bot join a voice channel but when im trying to use this command, the shard restart itself
const { joinVoiceChannel } = require('@discordjs/voice');
module.exports = {
name: 'test',
run: async (client, message, args) => {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.reply('Join channel pls.');
await joinVoiceChannel({
channelId: voiceChannel.id,
guildID: message.guild.id,
selfDeaf: true,
adapterCreator: message.guild.voiceAdapterCreator,
});
},
};
my bot doesn't joins my vc but still says that i'm connected
const connection = await joinVoiceChannel({
channelId: message.member.voice.channel,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
console.log("connected");
const player = await createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
const resource = createAudioResource('./assets/pub-carglass.mp3');
await player.play(resource);
await connection.subscribe(player);
console.log("playing pub-carglass.mp3")```
how can a bot join a stage Channel?
Hello, with the basic example, how can I play the song in loop?
Show me where you defined client in main file
Same way as you join a voice channel
could you explain?
You need to form a queue mechanism
Is there any way to make player stream a local file like in v12 and not buffer it for like 2 seconds first?
I don't see anything there that could help me
hi how can ı get connections and connection.subscribe
getVoiceConnection function is not working
What do you mean it's not working?
You have to have created the connection prior to make it work. https://discordjs.guide/voice/voice-connections.html#creation
Those are the exact steps you need to take in order to create a connection and subscribe to an audio player.
mean ı must use create connection for subscribe ?
yes
is there a event when player done playing resource ?
player.play(resource);
connection.subscribe(player);
Can someone explain how bot join a voice channel
guide in pins
state should switch to idle - that's also explained in the guide iirc
in Player class ?
AudioPlayerStatus.Idle
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] });
you need GUILD_VOICE_STATES intent
ohh okay thanks
it works now 👍
so u need to check every like 5m ? 
you don't need to check - you can simply use this: player.on(AudioPlayerStatus.Idle
this can all be found in the voice guide...
how can i play audios on seperate voice channel
like user1 talking > play audio into user2 channel
@subtle granite must be different guild
I know you can't do it on the same server
yeah ik
how do you make a queue system? (ping me when you repond please)
Error: aborted
at connResetException (node:internal/errors:691:14)
at TLSSocket.socketCloseListener (node:_http_client:407:19)
at TLSSocket.emit (node:events:406:35)
at node:net:672:12
at TCP.done (node:_tls_wrap:580:7)
You need to use node 16
Yeah, already using..

Haha ima assume this is a question yall get alot, but how do you join a voice channel?
Use the joinVoiceChannel function from the voice package
Hello! I'm getting this error when I try to install @discordjs/opus. https://sourceb.in/wSgs0dtn95
Ping me with you answer please.
Thanks!
The guide in the pins goes more into detail (voice connections section)
Will check out
someone know how to create a voice channel?
im confusing LMFAO
It's not actually in DJS voice.
https://discord.js.org/#/docs/main/stable/class/GuildChannelManager?scrollTo=create
i cant install sodium
Try using libsodium-wrappers instead, it might work for you
Hello! I'm getting this error when I try to install @discordjs/opus. https://sourceb.in/wSgs0dtn95
Ping me with you answer please.
Isn't oldMember only suppose to update when someone leaves a call? From what it looks like newMember and oldMember are the exact same thing.
You're missing essential build tools. Are you on Linux?
No I am not on Linux.
What are you on...
Windows
Is this in a container or something? I see it looking at a path of /home/container.
My bot path is /home/container
All of my js files are in there.
OK but Windows doesn't have file paths like /home/container.
I know. But what is the problem with that?
How you install the build tools depends on the platform it's executed on.
You need to make sure these requirements are fulfilled for your platform: https://github.com/nodejs/node-gyp
I need to install build tools? Ah. I know how to do that
Yeah. node-gyp is the C++ addon compiler and it needs make and friends to do that of course (which yours says is missing).
Am I the only one who is seeing a 404 in that error ??
Yup he is getting some errors with sending packet, There is no release like
opus-v0.5.3-node-v83-napi-v3-linux-x64-glibc-2.28.tar.gz
On this site : https://github.com/discordjs/opus/releases
@frank night Can you try installing discordjs/opus in a separate new folder by :
npm i init -y
npm i @discordjs/opus
thanks 
You are right indeed. I didn't catch that, just the glaring gyp ERR! stack Error: not found: make haha.
how to let bot join a voice channel
https://discordjs.guide/voice/voice-connections.html#creation (joinVoiceChannel).
HAHA
const { joinVoiceChannel } = require('@discordjs/voice');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
connection.on(VoiceConnectionStatus.Ready, () => {
console.log('The connection has entered the Ready state - ready to play audio!');
});
then the bot will join the vc?
Yes but you need GUILD_VOICE_STATES intent also
thanks
Make sure to define channel as member.voice.channel

const { joinVoiceChannel, VoiceConnectionStatus, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
const connection = joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.channel.guild.id,
adapterCreator: message.channel.guild.voiceAdapterCreator,
});
connection.on(VoiceConnectionStatus.Ready, () => {
console.log('The connection has entered the Ready state - ready to play audio!');
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
}
});
player.play(stream);
C:\Users\User\Documents\GitHub\lolol\node_modules\@discordjs\voice\dist\audio\AudioPlayer.js:221
resource.playStream.once('error', onStreamError);
^
TypeError: Cannot read property 'once' of undefined
at AudioPlayer.play (C:\Users\User\Documents\GitHub\lolol\node_modules\@discordjs\voice\dist\audio\AudioPlayer.js:221:29)
at Client.<anonymous> (C:\Users\User\Documents\GitHub\lolol\index.js:36:16)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
What is stream ??
You can’t pass a stream into player.play
stdout
Isn’t stdout a writable stream?
yes
Meaning it takes input
Like console.log("foo")
Bc even if you create the resource as described in the guide, it takes a ReadableStream
voice expects input to send to the vc
oh
How to detect if member isnt in a voice channel?
Documentation suggestion for @vast magnet:
(event) Client#voiceStateUpdate
Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
why doesnt this play audio in the channel?
player.play(resource);
i have defined player and resource
resource code
const resource = createAudioResource('./cool.mp3');
it joins channel and doesnt play audio
Did you subscribe the connection to the player?
CreateAudioResource never takes relative path
Do this if you want to play.
const path = require('path')
const resource = createAudioResource(path.resolve('./cool.mp3'));
still only joins vc doesnt play the sound
Should i put the full path in there?
Have you done connection.subscribe(player) ??
no
Do it then
thanks it works
Would highly recommend reading through the guide
when i do /pause it doesnt pause the sound
Console.log(player.pause()) ??
i get false value
That means that player is either not running anything or it was not successful in pausing the player
How can i check how many people are using specific vc?
voice.channel.members
Documentation suggestion for @rustic pelican:
VoiceChannel#members
The members in this voice-based channel
my player is running but it doesnt pause
Should i change this code? player.pause();
Add this code above pause command :
console.log(player.status)
Then show me console.log

how wud i use message.member.voice.channelID with slash commands?
interaction.member.voice.channelID?
Documentation suggestion for @elfin lake:
Interaction#member
If this interaction was sent in a guild, the member which sent it
o h k
Quick question; why is my bot deafened?
How to know when the bot joins a voice Channel ?
@discordjs/voice deafens your bot by default when joining a channel
I see. What if I wanted to make voice commands?
set selfDeaf to false in the join config
Ah, got it. Thanks!
How do I set a highWaterMark?
Not a issue of discordjs/voice ask ytdl-core author
It was possible in v12
Not anymore
there no dispatcher anymore that would extend a stream
so thats y its not possible anymore
Has the voiceOld been updated?
whats that?
(parameter) voiceOld: Discord.VoiceState
that should still work like it did on v12
VoiceState didnt have that big of change as the rest of voice
why i cant use ${client.voice.connection.size} more ?
Bc d.js doesn’t handle voice connections anymore
You have to use the getVoiceConnections function to get all voice connections
I might be doing something wrong, but on an interaction the Voice Channel does not change for me, e.g. the state that I was in before application launch is the only one I can read.
console.log(interaction.member.voice.channel.id) // => null
// Joining Channel
console.log(interaction.member.displayName) // => null
// Restarting Application
console.log(interaction.member.displayName) // => 8239...
Curiously, other attributes do change, e.g. if I change the nickname, it does show
console.log(interaction.member.displayName) // => mäh
// changing nick to "Test"
console.log(interaction.member.displayName) // => Test
Do any of you guys know how I "refresh" this or something?
Maybe you are missing GUILD_VOICE_STATES intent
Ah yes, my bad, sorry. The changes in v13 are a bit unclear to me
No Problem
how can I check if my bot is outputting audio?
guys im having an issue download @discordjs/opus, can anyone help
whats ur error?
1 sec
cuz that will tell u what the problem is
in console i get undefined
maybe try updating node gyp?
how may i do that
wait gimme a sec
npm i node gyp@latest?
i think i was lookin at somethin else
idk tbh
well thx for ur effort
Hello, how define ressource if ressource is a Youtube video ?
some say to do this npm install -g node-gyp
ill try that
might help
didnt help :(
Create a new folder and then do npm init -y
Then install discordjs/opus there and then tell me
npm update?
i am on 7.20.3
im saying run the command npm update
idk but it could work or do what NIP said
That means your player is player is not in playing state. That means it can't be paused
but it is playing audio in the voice channel
@bleak heart worked ??
omg yes
what did u do?
its on another bot
That means your code is creating new player every time.
im still getting the error on my current bot
@bleak heart Transfer code to new folder and do above ^^
so where should i put player variable at?
It is your code, you need to figure out a way to check if existing connection has a player or not. If yes then use that player.
connection.state.subscription.player if connection.subscribe(player) is done.
if i do this code when pause command is recieved it stops the audio from playing i dont know if it paused or just stopped audio from playing
if(connection.subscribe(player)) {
console.log('test')
}
should i use functions?
Yes, that will stop the audio since new player is subscribed to that connection.
See in your code, what are you doing wrong. Maybe think as a bot, this will help you realize your mistake.
Error: Cannot find module 'C:\Users\myname\Desktop\Naxeys-Discord-radio\node_modules\@discordjs\voice\dist\index.js'. Please verify that the package.json has a valid "main" entry
any idea on how to fix this
please DM or @pure pewter me
Blow out your node_modules and reinstall?
seems to be the only solution ig
Doesn't seem like a particularly bad solution...quick and easy? 
Do npm init -y quick and easy way
HAHAHAHA 🤣 🤣 🤣 🤣
I'm having issues playing audio, I have an mp3 file at the path, and there is already a connection open, it's a top level variable in the file. I'm not getting any errors.
/**
*
* @param {*} info
* @param {Discord.Interaction} interaction
*/
async function playVideo(info, interaction) {
if (!connection) {
return interaction.editReply(
"Sorry, you can't do that! \n`Error Code: 3 | BOT_NO_VC`"
);
} else {
const videoPath = path.resolve("../rdt-rdr-bot/download/video.mp3")
const video = voice.createAudioResource(videoPath)
console.log(video)
audioPlayer.play(video)
sub = connection.subscribe(audioPlayer)
interaction.deleteReply()
}
}
Where's connection defined there?
It's defined higher up, before the function
at top level, so it exists at that point
let me put it in a bin rq
When you go to change e.g. the speed of some audio, is there any way to get the current timestamp of the stream?
Or maybe another way to ask that is, can I clone the stream somehow with additional/different arguments.
Now I'm not sure what's wrong, I did some logging and found that it buffers and plays like normal, but it switches instantly, with the resource never starting.
log
buffering false
playing false
idle undefined
code for log
audioPlayer.on("stateChange", (n, o) => {
console.log(o.status, o.resource?.started)
})
relevant code
/**
*
* @param {*} info
* @param {Discord.Interaction} interaction
*/
async function playVideo(info, interaction) {
if (!connection) {
return interaction.editReply(
"Sorry, you can't do that! \n`Error Code: 3 | BOT_NO_VC`"
);
} else {
const videoPath = path.resolve("../rdt-rdr-bot/download/video.mp3")
const video = voice.createAudioResource(videoPath)
console.log(video.playbackDuration)
audioPlayer.play(video)
sub.unsubscribe()
sub = connection.subscribe(audioPlayer)
interaction.deleteReply()
}
}
Full code for file
https://pastebin.com/7E29KAN8
What could be causing this error?
Error: Did not enter state ready within 30000ms
It's very strange because it only showed this error after hundreds of times playing audio.
The code i'm using to avoid the error:
if (newState.channel?.type == 'GUILD_STAGE_VOICE') return;
if (newState.channel?.joinable && !newState.channel?.full) {
playAudio(oldState, newState);
}
Make sure you have the guild voice states intent
yes, I have that intent.
Could it be a network issue? (I'm using a VPS so very unlikely)
Does it happen every time you play audio, or just that one time?
Just that one time
Hard to rly tell if your can’t reliably reproduce it
It could be network issue or smth in ur code slowing down the entire bot
Yep, I know. I asked in case there was any known bug or something
thanks anyway!
Show me the code how you actually run these functions ( JoinVC, playVideo ) in a command.
//video.js
/**
*
* @param {string} url
*/
async function downloadVideo(url, interaction) {
const fs = require("fs");
const ytdl = require("ytdl-core");
const vc = require("./vc.js");
ytdl(url, { filter: "audioonly" }).pipe(
fs.createWriteStream("./download/video.mp3")
);
const info = await ytdl.getInfo(url);
vc.playVideo(info, interaction); //HERE
return;
}
exports.downloadVideo = downloadVideo;
//controlPanel.js
async function handleSlectMenu(Discord, Client, interaction) {
const v = require("./video.js")
interaction.deferReply()
console.log(interaction.values[0])
await v.downloadVideo(interaction.values[0], interaction) //HERE
}
//....
if (interaction.customId == "join") {
vc.joinVC(Discord, Client, interaction)
}
ControlPanel.js just manages the button message
all interactions get forwarded to it
This is purely semantic but why call it playVideo if it strictly does not play video.
Can you console.log(videoPath) ??
It plays the downloaded video to the audioPlayer
/root/bot/download/video.mp3
Which is the correct path
Your file path here includes a rdt-rdr-bot folder which I can't see it in your above reply ^^
This tells me that this code file and vc.js are in same folder, so different path for video.mp3 ?????????????
I edited the reply because I think the bot's name stupid, my mistake 😆
the mp3 file is in a different file, let me get a ss
Try changing to videoPath = path.resolve('./download/video.mp3')
Still no audio, and the path didn't change
Do you have GUILD_VOICE_STATES intent ??
Yes
If I wanted to stream it, do pipe it into the audio player?
That might not work
After audioPlayer.play(video), add this line :
console.log(audioPlayer.checkPlayable())
It said false
That means your audio resource has some issues
AudioResource is not playable by audioPlayer
Alright, I just tried playing video.mp3 in VLC and it works fine, is it that I'm doing it too fast and the video hasn't fully downloaded?
As far as I think, you are not letting this pipe to complete and you are creating a audio Resource of a incomplete file maybe
I changed it to
ytdl(url, { filter: "audioonly" }).pipe(
fs.createWriteStream("./download/video.mp3")
.on("finish", async () => {
const info = await ytdl.getInfo(url);
vc.playVideo(info, interaction);
})
);
but it's never firing
I'm having an issue where the audio finishes within a second of it saying Enqued <track>. I am using the sample music bot example by the way.
Any common reasons to why it may be happening?
Woah!
@carmine timber It just started playing after 5 minutes
Very odd
my code is getting stuck on the line where it creates the audio player
const player = Voice.createAudioPlayer({debug: true});
Why Is my channel.join function not working?
i'm sure the people here would be glad to see some code
Just I do channel.join() but it shows TypeError: channel.join is not a function
@quasi tundra
//const player = Voice.createAudioPlayer({debug: true});
// const resource = Voice.createAudioResource(MP3Path, {
// metadata: {
// title: "Bad Apple!! - nomico"
// }
// });
it got stuck on both of these parts
my code hangs anytime i call a function from the Voice library
I can't import everything through 1 object
import {destructure here...} from "@discordjs/voice"
ok it works now
It's now in @discordjs/voice with the joinVoiceChannel function
https://discordjs.github.io/voice documentation here
djs voice example please
Link is in the pins
i need js, not ts
Just ignore the types
Also use const { joinVoiceChannel, … } = require("…") in place of the import
Go to examples -> radio-bot -> index.js
The guide in the pins is more helpful imo
How to play ffmpeg file?
i have connection, how to play something there?
Hello. When I get the member's voice state (member.voice), It gives me the correct channel, But when I go to another channel and run the command again, It still shows me the previous channel. Until I restart the bot. How can I fix it?
Enable the guild voice states intent
hello i am getting this error -
TypeError: Cannot read property 'once' of undefined
at AudioPlayer.play (C:\Users\a\Desktop\v13\djsv13\node_modules\@discordjs\voice\dist\audio\AudioPlayer.js:221:29)
at Object.module.exports.run (C:\Users\a\Desktop\v13\djsv13\commands\cmd2\play.js:130:12)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
My code -
You can't play youtube url like that
then?
ytdl-core
yea
ytdl-core allows you to filter out the audio only
and you pass that to createAudioResource?
const resource = createAudioResource(stream);```
does this download the audio all at once before playing or is it playing as it's being downloaded?
I'm basically trying to do the same thing and it wasn't working with downloading the youtube link so I tried with just a file on hand but it still won't play the audio
const ytdl = require('ytdl-core');
const path = require("path");
const filesystem = require("fs")
exports.run = async (bot,message,args) => {
const connection = voice.joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.channel.guild.id,
adapterCreator: message.channel.guild.voiceAdapterCreator,
});
connection.on(voice.VoiceConnectionStatus.Ready, () => {
console.log('The connection has entered the Ready state - ready to play audio!');
});
const player = voice.createAudioPlayer({
behaviors: {
noSubscriber: voice.NoSubscriberBehavior.Pause,
}
});
// ytdl("https://www.youtube.com/watch?v=sGyBWNVNdP0", {filter: 'audioonly'}).pipe(filesystem.createWriteStream('./downloads/music.mp3'));
const videoPath = path.resolve("./downloads/succ.mp3")
const audio = voice.createAudioResource(videoPath)
player.play(audio);
}
exports.help = {
name: 'Play'
}```
am i blind
the connection never subscribes to the player?
that might be why
What's that then? literally just connection.Subscribe(player) ?
.subscribe, but yes
cheers pal
damn, the stream is firing an error, ECONNRESET and it's causing the bot to just hang even after i handle it
Sometimes there's an unfinished YouTube-dl process. Do you have any idea why?
yeah I might be having the same issue. The youtube stream plays now but it cuts out about 20 seconds in, no errors in the log.
this 100% works with local files
stream.on("error", stream.destroy);
const resource = createAudioResource(stream);```
this is the only thing i changed, it hangs
ytdl is just the default export of ytdl-core
I've been able to get the entire song to play once.
could it possibly be a bitrate issue?
how can i manage volume?
theres some info options similar to the filter I used in the code block up above
dispatcher.setVolume((volum/100));``` from https://www.tabnine.com/code/javascript/functions/ytdl-core/ytdl
Is there a documentation for the new voice library?
or I can only find stuff in the guide?
I just got this now
I get this error
at ClientRequest.<anonymous> (C:\Users\Utilisateur\node_modules\miniget\dist\index.js:210:27)
at Object.onceWrapper (node:events:514:26)
at ClientRequest.emit (node:events:394:28)
at HTTPParser.parserOnIncomingClient (node:_http_client:621:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
at TLSSocket.socketOnData (node:_http_client:487:22)
at TLSSocket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:312:12)
at readableAddChunk (node:internal/streams/readable:287:9)
at TLSSocket.Readable.push (node:internal/streams/readable:226:10)
Emitted 'error' event on AudioPlayer instance at:
at OggDemuxer.onStreamError (C:\Users\Utilisateur\Discord\Bots\keymey\node_modules\@discordjs\voice\dist\audio\AudioPlayer.js:213:22)
at Object.onceWrapper (node:events:514:26)
at OggDemuxer.emit (node:events:406:35)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)```
with this code ```js
async playSound(channel, guild, sound) {
const connection = await joinVoiceChannel({
channelId: channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
})
//if (channel.type == "GUILD_STAGE") guild.me.voice.setSuppressed(true);
console.log("Joined #" + channel.name)
const player = await createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Stop,
},
});
const resource = await createAudioResource(sound);
await player.play(resource);
await connection.subscribe(player);
}```
oh
problem fixed 👍
how to configure volume?
dispatcher.setVolume((volum/100));```
from https://www.tabnine.com/code/javascript/functions/ytdl-core/ytdl
the fix was?
Ok ;-;
What is AudioResource.volume?.setVolume()'s range? Is it 0.1 ~ 1?
I'm getting this error when I try to install @discordjs/opus. https://sourceb.in/UAqHfrUABE
huh, Are you from v13 or v11 ??
Range is 0 - Infinity ( maybe upto some extend, but IDK about that ) where 0 stands for 0% volume and 1 stands for 100% volume
create a new folder and do npm init -y and then install opus again
What should I name the folder?
\
updating ytdl-core
v13 I just got that from the link below it