#archive-voice
30636 messages · Page 6 of 31
i did the same thing but i can't stil hear anything.
with djs13, stage channel are supported?
yes
and, its like "voice.channel" ?
Yes just look at this :
https://discord.js.org/#/docs/main/master/class/VoiceState?scrollTo=channel
You will get stage channel or voice channel class according to channel type
okay
txbut if I don't have the intents it detects it anyway?
You don't need indents for getting channel info.
indents are only meant for listening to events like messageCreate, messageDelete etc.
messageCreate its "message" on djs12?
Yes
uh, and i have a certified bot, and he dont have intents
djs 12 or 13 ??
12
In djs v13, it is mandatory to have intents
because it does not require a lot of event
so my bot will become unusable?
No adding intents is just a one line code
See this
i mean
?v13-intents
The master branch of Discord.js requires you to choose suitable intents (as it uses a new version of Discord's API)
For information on using websocket intents: https://discordjs.guide/popular-topics/intents.html
Note that this is a v12 guide - in master intents are provided directly to the ClientOptions:
- const client = new Client({ ws: { intents: ['GUILDS', 'GUILD_MESSAGES'] } });
+ const client = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] });```
okay
These are different intents as it contains some private data,
Rest intents : https://discord.com/developers/docs/topics/gateway#gateway-intents
oh, okay lmao I was so scared
XD
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of null ```
```js
let channelid = message.member.voice.channel.id
let channel = message.guild.channels.cache.get(channelid)
await channel.join()```
i cant make this?
Your channel.join is wrong code.
djs v12 or 13 ??
djs 13
djs 13 has removed those properties.
Now you need to use new voice api in djs v13.
See this to join in a voice channel : https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#creation
To install new voice module type : npm i @discordjs/voice
nice tgx
What is a good substitute for ytdl-core, ytdl?
https://www.npmjs.com/package/youtube-dl-exec it also work with SoundCloud (refer to bot examples in the lib of this repo for help)
Thks
Should I create one player per guild playing?
if you want to play different streams in each guild, yes
if you want a radio style bot, with one stream for all guilds, no
Got it, very thks
client.on('message', async message => {
const prefix = "!";
if(message.author.bot || !message.guild || !message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase()
if(command == 'record') {
if(!message.member.voice.channel) return;
const stream = await message.member.voice.channel.join()
console.log(stream)
}
})
Error:
(node:7904) UnhandledPromiseRejectionWarning: TypeError: message.member.voice.channel.join is not a function
const channel = message.member.voice.channel
joinVoiceChannel({
channel: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
})```
its now in @discordjs/voice
how can i define this?
i just took that from the examples, you can find them here https://github.com/discordjs/voice/tree/main/examples
Hello, do you have a solution for this error? Error: Did not enter state ready within 30000ms
let voiceChannel = message.member.voice.channel;
let connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guildId, adapterCreator: voiceChannel.guild.voiceAdapterCreator });
try {
entersState(connection, VoiceConnectionStatus.Ready, 30000);
} catch (err) {
connection.destroy();
console.log(err);
}
Okay I just replaced guildId by guild.id, my bad x)
Any tips in how to stop the Aborted Connection error?
Or causes of it
Show me your intents.
what is wrong?
@celest basalt,can you help me?
No
Well, who can help me with my problem?
Whoever comes into this channel to help. Stop trying to ping
?r6
6. Do not mention or DM individual members just for help. You may not get a reply quickly, if at all. Post your question in the public channels where more people can see it.
how do i disconnect the bot from a voice channel?
have you check the intent?
so... about a month ago I started messing around with the new voice stuff to see if it was worth implementing it into one of my projects. I got it working for what I wanted - basically when a particular user joins a vc I wanted the bot to also join and play an audio file. it worked fine but I disabled it because it was annoying a few people.
I just tried to add it back so I can further tweak it and am finding it now to not be working. I know this is still in dev and I'm sure something was changed that affects my code but I'm wondering if someone might be able to just have a little look over it and give their two cents please
const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior, createAudioResource, StreamType } = require('@discordjs/voice');
module.exports = class voiceStateUpdate extends baseEvent {
constructor() {
super('voiceStateUpdate');
}
async run(client, oldState, newState) {
const nope = 1;
if(newState.id === '139152491496472576' && !oldState.channel) {
const connection = joinVoiceChannel({
channelId: newState.channelID,
guildId: newState.guild.id,
adapterCreator: newState.guild.voiceAdapterCreator,
});
const player = createAudioPlayer({
noSubscriber: NoSubscriberBehavior.Pause,
selfDeaf: true,
});
const resource = createAudioResource('https://okie.eu/i/mikaj.mp3', {
inputType: StreamType.Arbitrary,
});
player.play(resource);
connection.subscribe(player);
if(newState.id === '139152491496472576' && newState.selfMute === true && connection) {
connection.destroy();
}
}
}
}```
user joins the vc, and provided they weren't already in a vc on the server then the bot should join the same vc and play the audio file. the user can then just self mute once forcing the bot to disconnect again. however with that above code, the bot doesn't join nor does it emit any error to tell me why
but it did work about a month ago
nevermind. I see why now - part of this odd pattern of changing ID to Id everywhere
He told he joined vc, but not able to play audio.
So how does not playing (no sound) related to intents ??
Use ytdl-core-discord module instead of ytdl-core.( https://www.npmjs.com/package/ytdl-core-discord)
OR for most efficiency, try to use youtube-dl exec as show here (https://github.com/discordjs/voice/blob/main/examples/music-bot/src/music/track.ts)
the bot doesn't join nor does it emit any error
Show me code where you defined Client.
not me, the message is gone lol
LOL
broadcasts are more valid in v13?
how would I debug buffering issues? only thing I found was AudioPlayer debug event which just logs state changes
Every time I try to execute```js
newMember.member.voice.kick()
`Error [VOICE_STATE_UNCACHED_MEMBER]: The member of this voice state is uncached.`
How to fix this or how to cache the user?
There were no such problems before..
https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=fetch
newMember.member.fetch(true)
Thanks, премного благодарен
You can't debug that with audio player. Rather, you can do this
<AudioResource>.on('error', () => <your callback>)
No problem
how can i get this function in V13?
connection.receiver.createStream()
This is incorrect, should attach the error listener to AudioPlayer instead
let newConnection = joinVoiceChannel({ channelId: VC.id, guildId: VC.guild.id, adapterCreator: VC.guild.voiceAdapterCreator });
entersState(newConnection, VoiceConnectionStatus.Ready, 60000).then(connection => {
UnhandledPromiseRejectionWarning: ReferenceError: joinVoiceChannel is not defined how come
did you require it from discord.js/voice?
why do i need to do all this authenticating shit when trying to install /voice
or was it @discordjs/voice
@discordjs/voice
Package subpath './voice' is not defined by "exports"
inve installed sodium @edgy burrow
still got the same error...
can createAudioResource handle URL's?
Hi, tell me if the bot might want to Stage?
How would I have my bot leave the voice channel after playing an mp3 file?
that doesn't really help, all I get is https://cdn.mbr.pw/31636712815984826.png
it's just stuck on buffering 
yeah it only happens when trying to play live radio streams after a youtube video has been played, very weird 
it also appears that calling AudioPlayer#stop while its buffering doesn't actually ever stop it/changes state to idle 
nvm I had to do AudioPlayer#stop(true) 
how can i use:
new AudioReceiveStream()
Oh i posted my issue in the wrong channel i think
This is the discord.js@dev voice right?
yes
well @discordjs/voice which is needed on v13 for voice
how do i prevent when doing a process, it stops suddenly?
give more context maybe?
when the player is playing and doing some process (like yt-search api), the player suddenly stops and after a few seconds (after the process), the player will play back.
how do i prevent that?
in my experience, it is because of the search package. I have the same issue before, forgot what package I used for searching youtube, and notice that the package dependency that make it eating up cpu/ram thus interrupting the song playback. I change to other search package, which is lighter the issue not occur anymore. Have a try, I can't guarantee, but that's that
Any tips in how to handle / prevent the Abort error?
What do you use now?
how can i skip a song?
I coded that everytime the player enters idle it searches for the next song, so in my implementation I use player.stop() to skip. If (!song) it just waits a time and disconnect
how about seeking?
broadcast has now unavailable on v13 ?
@worthy coyote everything is now a broadcast instead
You can make an audio player, and then play that across as many voice connections as you want
The audio player is essentially the broadcast here
yes but my bot wan't play, i have follow all steps of doc
what's the correct way to destroy the AudioPlayer? (so it cleans everything up)
hey with the @discord/voice
const subscription = new MusicSubscription(
joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
}),
);
im getting an error with the adapterCreator
Type 'InternalDiscordGatewayAdapterCreator' is not assignable to type 'DiscordGatewayAdapterCreator'.
Hello, is it normal that when my bot plays music on a vc, I have this error: DeprecationWarning: Socket.prototype._handle is deprecated?
node:events:371
throw er; // Unhandled 'error' event
^
AudioPlayerError: aborted
Emitted 'error' event on AudioPlayer instance at:
at OggDemuxer.onStreamError
Keep Getting this error after a few minutes of playback :/
"@discordjs/voice": "^0.5.4", "sodium": "^3.0.2", "yt-search": "^2.9.0", "ytdl-core": "^4.8.3"
Any Fix Please?
npm i @discordjs/opus
error:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/container/node_modules/@discordjs/opus/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/container/node_modules/@discordjs/opus/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/container/.npm/_logs/2021-07-18T18_34_21_561Z-debug.log
connection.pause() is not a function?
ig u meant to do audioPlayer.pause? not connection.pause
oh
so what package if you know? should i use to like get songs by urls and make them like .mp3 format like ytdl core?
i personally use ytdl-core
ytdl-core works with djsv13 can u show an ex
ill see if i got a simple one
just a sec
welp i dont have a simple one unfortunately
but it should be quite straightforward
oh could you show me one even advanced s fine
uhhh the one i got is really just a mess xd
just try to use it urself. If u get any problems i can do my best to assist
ok thx, error: Status code: 404
updating ytdl-core should fix that
are there any plans to put @djs/voice into the client like the old voice code
or is it gonna stay used via functions exported by the module
eg are we going to have VoiceChannel#join again or will it be @discordjs/voice#joinVoiceChannel for the forseeable future
it will stay as a seperate library
how to get the buffer from ytdl-core? like ex: <ytdl after func>.pipe(somewaytostoreit())
ytdl returns a readable stream. Which as itself is a stream of buffers.
hm? idk understand.
Is there a way to play a livestream from ytdl?
When I try this, the bot disconnects after 5 seconds without error
how do play a song even?
With ytdl?
let connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guild.id, adapterCreator: voiceChannel.guild.voiceAdapterCreator });
entersState(connection, VoiceConnectionStatus.Ready, 30000).then(() => {
ytdl.getInfo(args[1]).then(video => {
let song = { title: video.videoDetails.title, url: video.videoDetails.video_url, author: message.author.id };
let stream = ytdl(song.url, { filter: 'audioonly' });
let resource = createAudioResource(stream);
player.play(resource);
entersState(player, AudioPlayerStatus.Playing, 5000);
})
})
yep sorry
try this with a normal video
with a normal video it works without problems
just when i try with a stream, the bot stops after 5 seconds
I think it doesn't work with livestreams because there's no playbackDuration (livestreams do not have limits), so is there a way to resolve that?
yes, idk why then
What are good packages to handle spotify playlist and links?
not djs
lmao
I use spotify-url-info to grab the info of spotify urls
works well with tracks, playlists, albums
and it's easy to use
Thnks
So do you have a solution for playing a livestream on a voice channel?
@discordjs/voice contains everything for voice now right? including joining a voice channel?
yes
cool thanks
is the discord.js adapter here (https://github.com/discordjs/voice/blob/main/examples/basic/adapter.ts) built into the library somewhere as a default (or in discord.js), or should i be rewriting one for my use-case?
<guild>.voiceAdapterCreator will create a new one for the guild is build in
Hey there, i have my bot joining however its not playing the audio and it is also not giving any errors
im attempting to play a mp3 from a link e.g https://mylink.com/song.mp3
//Code for reference
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause
},
});
let connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guild.id, adapterCreator: voiceChannel.guild.voiceAdapterCreator });
entersState(connection, VoiceConnectionStatus.Ready, 30000).then(() => {
let resource = createAudioResource(songurl);
player.play(resource);
entersState(player, AudioPlayerStatus.Playing, 5000);
//as i said, song url is formed as https://mylink.com/song.mp3
it did that for me, npm updates fixed it. If that doesn't fix it, idk then sadly
ok I will try this, thanks
anyone help??
try logging player state changes
how so? @brisk urchin
nothing happens...
how do i play sound from youtube (i made the Video Finder)
It didn't worked :/
why that code doesn't playing the audio
thats not playing the auido but when i do a mp3 link from another website it works but when i get from youtube is not works help pls
There's no any errors
i fixed don't use opus
how do i seek to a part of the current song?
ytdl(url, {start: start time, end: end time});
as ms
im not using ytdl
what u use
im using my own links
then idk
hello i have a question about my memory leak situation i use very similar concept to https://github.com/discordjs/voice/tree/main/examples/music-bot for my q and etc. and i suspected when i destroy the voice connection then deleted the musicsub object i have 1 active handler more from the original value of active handler before the voice connection and this dont happen when the played resource ends then i destroy connection and delete the voice sub is this a library issue or a something me to handle as a user and how can i handle this?
how do i seek to a part of a song that is about to be broadcasted?? is there the same {seek: <seconds>} functionality like how there is in v12
?docs
@subtle granite, what would you like to search for?
Type cancel to cancel the command.
voice
is there ANY way to do this????
can i have help please ?
Song is ready to play!
/root/PrivateBot/Coins/node_modules/@discordjs/voice/dist/util/Secretbox.js:27
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, libsodium-wrappers, or tweetnacl.
I have already install sodium
how can i define a start time for a song?
like if i want to start 5 seconds in?
Install libsodium-wrappers and then try
You can create an FFMPEG instance from prism-media module and then pass these arguments to that FFMPEG instance.
const prism_media = require('prism-media')
const { createAudioResource, StreamType } = require('@discordjs/voice')
const FFMPEG_OPUS_ARGUMENTS = [
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
];
// Above code should be at top
const url = < your url>
const ffmpeg_instance = new prism_media.FFmpeg({
args : ['-ss', '5000ms', '-accurate_seek' ,'-i', url, ...FFMPEG_OPUS_ARGUMENTS ]
})
var source = createAudioResource(ffmpeg_instance, { inputType: StreamType.OggOpus , inlineVolume : true })
This will start song at 5 seconds.
i have done this however no audio is being outputed
nvm, i had my audio output on discord disabled
How can I check if a user joined a stage channel using voiceStateUpdate?
If ur using 13-dev Check if newState channel is of type GUILD_STAGE_VOICE
and how can I check the type? https://discord.js.org/#/docs/main/master/class/VoiceState?scrollTo=channel
found it :) newState.channel?.type == 'GUILD_STAGE_VOICE'
Any major updates from v0.5.1 to 0.5.4? It stopped working when I updated and returns no errors
how can i make an dispatcher e.x
dispatcher.on('finish', () = {
// code to get song from queue
})```
dispatchers don’t exist in v13 if i’m not wrong
yes they dont
the closest to it would be the AudioPlayer/AudioResource
is it possible to edit the ffmpeg arguments mid stream?
no. U will have to respawn the process with the new arguments
Hpw can I make an event when the song ends
I have this:
connection = joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: member.guild.id,
adapterCreator: member.guild.voiceAdapterCreator
});
But I get an error for the adapterCreator. It says:
TS2322: Type 'InternalDiscordGatewayAdapterCreator' is not assignable to type 'DiscordGatewayAdapterCreator'.
...
What am I doing wrong here?
adapterCreator: member.voice.voiceAdapterCreator
Hi, I've created an audio resourse in my client ready by launching a radio on the bot. But if I want to change the radio with a command, it doesn't change. I think I have to replace te audio resource somehow but I need some help. This is what I am using to play/modify the radios:
is therer anyway to speed up the seeking process? it takes a good 10-15 seconds for my music to start playing while seeking
I have a PCM stream, what do I need to do to change it into an opus
(Or any bot readable) stream?
I'm trying
args: [
'-analyzeduration', '0',
'-loglevel', '0',
'-f', 's16le',
'-i', PCMStream,
'-acodec', 'libopus',
'-f', 'opus',
'-ar', '48000',
'-ac', '2',
],
});```
But the bot stays silent every time I try to play encoder
@spiral jetty i did this:
let resource = createAudioResource(ffmpeg_instance, { inputType: StreamType.OggOpus , inlineVolume : true });
@spiral jetty one more thing, where did u get a list of arg's you can use for the encodeR?
Well there's this https://ffmpeg.org/ffmpeg.html
But that code I just found on the radio-bot example page https://github.com/discordjs/voice/blob/main/examples/radio-bot/index.js and messed around with variables attempting to get it to work
is it possible to identify what the user said in a voice channel?
You'd have to code that yourself, I recommend using an api
How know if my bot is connected to a voiceChannel?
which voice recognition API do you recommend?
https://cloud.google.com/speech-to-text/ @sonic torrent
ok
how do i install sodium?
i get this error when installing sodium
As it says, msvsVersion is not defined, check the npm page on how to install sodium on windows
okay 👍
You can't install sodium on windows as sodium supports msVersion upto 2015 and most of current users have higher msVersion like 2017, 2019 etc..
Moreover, windows-build-tools are also on msVersion 2017.
So ignore installing sodium, go for libsodium-wrappers.
In the pin guide, it show you how to
Or just go for libsodium-wrapper
If you have a PCM stream, you can play it with StreamType.Raw
The voice library can automatically encode PCM streams to opus for you
How can I make an event when the song ends
<AudioPlayer>.on(AudioPlayerStatus.Idle, fn) or 'idle' event.
discord cannot identify nor receive voice input through voice channels, so unless you code your own thing to send and receive, no
how do i change the playbackDration? like seeking
that worked thanks but is that per guild?
i want to make Music bot do i can make it with this new voice ?
use
createAudioResource
who had make the first music package for v13
see the music-bot example
what exactly do u mean by first music package
maybe if you subscribe the connections from other guilds in the same audioPlayer, it will emit the same event because it has the same player.
you can get the audioPlayer from a connection by <VoiceConnection>._state.subscription.player.
thx
The First Music Package on the npm page for v13
can u link it to me here?
what
can u give a link to that package?
who made it was my question
bcs i want to make it
im not exactly sure which package youre talking about
so could u please link it so i can take a look?
have anyone make it is my question
not work
(node:9052) UnhandledPromiseRejectionWarning: TypeError: connection._state.subscription.player is not a function
at playSong (C:\Users\Startklar\Desktop\Main\Discord Bot\JS v13\Dianos\functions\player.js:50:33)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9052) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9052) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with
a non-zero exit code.
afaik no1 is yet to create a 3rd party player package that uses v13 voice
okay
the player is a class. Not a function
oh s***
it says not a function.
what are you trying to do?
<audioPlayer.on('idle', fn)
you already have the audioPlayer in your code. you can just do player.on('idle', fn)
oh thx you
what do i make wrong
(node:16392) UnhandledPromiseRejectionWarning: C:\Users\Startklar\Desktop\Main\Discord Bot\JS v13\Dianos\commands\music\queue.js:21
let data = await find(value);
^^^^^
SyntaxError: await is only valid in async function
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at C:\Users\Startklar\Desktop\Main\Discord Bot\JS v13\Dianos\handler\index.js:10:22
at Array.map (<anonymous>)
at module.exports (C:\Users\Startklar\Desktop\Main\Discord Bot\JS v13\Dianos\handler\index.js:9:18)
That's basic JS. You need to make your function async (the one in the loop where you're using await)
i fixed it but thanks
yes i know, i am using a library to listen to users' voices.
which lib? @sonic torrent
artyom.js
where can i find music bot example with v13 but js not typescript
this is typescript i need javascript
U can convert it to js
Just remove all the typecasting etc
does anyone here made a audio cliping bot? I mean bot that records the audio in the voice channel and on some command makes an clip; cca 2 mins long record
Help me please, How i can play mp3 file in voice channel.
Change this line to interaction.guild.voiceAdapterCreator
You can't pass undefined to adapterCreator (by using ? in guild)
still error
Update djs to latest commit, or just ignore the typing chech
"discord.js": "^13.0.0-dev.07017a9.1626869177", Thi commit should remove the error
thank you i will try.
No, still have it error, just ignore it for now
Time to poke @vocal valley
There is a simple fix for this thing.
Just go to node_modules -> discord.js -> typings -> index.d.ts
Then add this line at top import { DiscordGatewayAdapterCreator } from '@discordjs/voice';
Then around Line 568 public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
Change this to public readonly voiceAdapterCreator: DiscordGatewayAdapterCreator;
This DiscordGatewayAdapterCreator has been marked for internal assessment and will be applied soon.
There already fix for it I see, just visited github, well either install it from github or wait for npm release
@vocal valley
I was getting this error.
https://user-images.githubusercontent.com/65385476/126593092-9ffec3b1-6663-4b6b-b59f-bed7a2c9f0d3.png
When I cloned and tested music-bot example again. (/examples/music-bot/src/music/subscription.ts)
Is this error with my typescript or a universal problem ??
I think your typescript maybe?
using setTimeout with 2 parameters like this is perfectly fine
How to fix that ??
🤷♂️
Resolve needs an argument to be passed. So setTimeout is asking for that argument for resolve only.
So it might be for all not specifically for me.
Should I make a pr for this OR you will do it yourself ??
I think got 1 person make a PR few hours ago when I go to the github repo
same issue
What node version you on @carmine timber ? Since I'm on v16.4.2 with jsconfig.json, no TS dependancy. TS doesn't bug me any error about it
v16.5.0
Try to run music-bot example as given in main branch. I got a setTimeout args error and let me know if you got same error or not.
Let me fork it and see
👍
@carmine timber thanks for PR, will review tonight, hopefully merge, then make a release
v16.2.0 no error, 
how to leave bot in voice channel ?
Type tsc -v in console.
Either this https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#deletion
OR
https://discordjs.github.io/voice/classes/voiceconnection.html#disconnect (Recommended as you can use voiceconnection rejoin function to join again without creating a new connection.)
No problem
earlier wrong directory, didn't npm install on the right folder, yup saw that error. done import util from 'util'; const wait = util.promisify(setTimeout) and it gone
thank a lot sir.
@carmine timber help me please. how to get listener count in voice channel ?
Do something like this :
var connected_users = 0
<VoiceChannel>.members.each((m) => connected_users++)
console.log(`Members connected = ${connected_users}`)
Sorry for first incorrect answer.
Then do interaction.member.voice.channel and rest above ^^
If your bot is also connected to same voice channel, then do something like this :
var connected_users = 0
<VoiceChannel>.members.each((m) => {
if(m.id === client.user?.id) return
else connected_users++
})
console.log(`Members connected = ${connected_users}`)
is there is any lavalink client who support discord.js v13?
new voice should have little effect on everyone using lavalink
just make sure your discord.js v13 client is up to date
hmm
currently my lavalink just load track but can't play track
doesnt really sound like a discord.js related issue. Lavalink handles all the sending of audio etc by itsself
hey so i was trying to make a lavalink music bot but it doesnt connect to lavalink node neither gives any error
This has nothing to do with us
ok
at Object.run (/home/container/commands/Music/stop.js:25:22)
at module.exports (/home/container/events/guild/messageCreate.js:262:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)```code: https://pastebin.com/ACDUZXbp
and bot was connected to a channel
erela.js supports i remember
const x = interaction.member.voice.channelId;
const y = interaction.guild.channels.cache.get(x);
if (y.joinable) {
y.join();
}
y.join() is not a function
Why doesn't this work anymore? Is there a new way to join voice channels in v13?
You need to use the new library. Check pinned messages
Hello there, I'm trying to port my bot to the new DJS Voice, and I believe I stumbled across a little issue: It seems VoiceConnection.channel has been removed. Is there a new way to get the currently connected channel?
Is the pr merged by which i can track active voice connections on all guilds? Previously client.voice.connections.size
What could be the causes of the Connection Aborted error?
Try using the DJS method: <guild>.me.voice.channel
Wait, does that exist in v13?
VoiceState#channel
The channel that the member is connected to
Wrong one
Documentation suggestion for @livid apex:
VoiceState#channel
The channel that the member is connected to
Right one
Alright I'm dumb, sorry for the bother. Thank you 🙂
By the way, if you don't mind me asking, should I use createAudioPlayer()'s return as the old dispatcher? idk, like storing it in a map or sth?
Sorry, this update got me really confused
how to set a description on a stage?
yes kinda
How can I join a voice channel on @discordjs/voice
Anyone?
I think that method has been removed. Now you need to manually get voice connections for each guild.
Does voice internally add any listeners to players
what's the event when a user disconnects the voice channel
Not new voice related. The discord.js event is voiceStateUpdate whenever the newState channel ID is not equal to the previous state channel ID or is null.
No, You need to manually add listeners for voiceStateUpdate.
BTW whenever a user disconnects, newState channel ID will always be equal to null. (It is how discord API works.)
And when a user connects to vc, oldState channel ID will be null.
The voice lib doesn't facilitate a connection to the bot gateway. On user disconnect should not get passed to the library unless it's the current user. (even then, the session invalidates and the lib handles that)
VOICE_STATE_UPDATE can transition between one channel ID to another. A user can move voice channels. The gateway doesn't send null and then the new channel ID. The channel_id is only null if the user is not in any voice channels anymore. The term "disconnect" is ambiguous, but my interpretation was that the user could move voice channels (which facilitates a disconnect from the previous voice channel and then connect to the new one)
old state channel ID is not always null for the same reason I already outlined.
I'd recommend doing more research on the raw gateway :)
How can i do that?
BTW why do you need that method ??
Want to show total active voice connections on stats command.
You need 2 things :
-
List of all guilds in which bot is in. (https://discord.js.org/#/docs/main/stable/class/GuildManager?scrollTo=cache)
client.guilds.cacheand get a array of Guild Class from here. -
And then use (
for (var x in <array>)) and then use https://discord.js.org/#/docs/main/master/class/Guild?scrollTo=voiceStates for getting active users in each guild.
Let me try. Thank you
@vocal valley Seen my PR ??
That's on the issue of meaning of disconnect not on my knowledge of raw gateway 🙂
You treat disconnect meaning in different way and I treated it in different way.
🙂
Hydrabolt, one more question, on this page voice-gateway-version is mentioned up to v4, but on my testing discord (discord chrome version) uses v5 for connecting to a voice channel. https://discord.com/developers/docs/topics/voice-connections#voice-gateway-versioning
So the developers docs are outdated for this respect ??
Websocket connects me to this url (wss://india6099.discord.media/?v=5).
Hey can you check out my question in #archive-djs-v12-voice-deprecated Lol
yep, it's just not documented for us yet so can't use it
will today, promise 😅
I dont understand this very well, can I get any examples?
Receiving audio examples are still in to-do list on its Initial Release
https://github.com/discordjs/voice/issues/92
https://github.com/discordjs/voice/issues/95
Only hydrabolt can help you to create a voice receiver example.
I see
I hope hydrabolt sees this-
I can't get voice connection when I restart bot but the bot is still in the voice channel. How can I fix it?
I use:
getVoiceConnection(guild.id).destroy()
First create a new connection and destroy that connection in every guild EZ.
Thanks and how can I play audio on a channel
You need to do this in 3 steps :
-
CreateAudioResource :- prepares audio that is going to play ( either local files or any stream (ytdl-core-discord or youtube-dl) ) [https://deploy-preview-595--discordjs-guide.netlify.app/voice/audio-resources.html#creation]
-
CreateAudioPlayer :- Player that is going to play that created resource [https://deploy-preview-595--discordjs-guide.netlify.app/voice/audio-player.html#creation]
-
Attaching Audio Player :- Then attaching this audio player to created voice connection. [https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#playing-audio] with subscribe function.
Thank you
You should be storing queues in a form of persistent storage so that you can have enough data to restore them and resume where you left off
@vocal valley sorry if you mind this ping, but pls help
hey, I would like to know how to fix this problem and if there is an error can you tell me ^^'
code:js module.exports = { name: 'join', description: 'Cette commande permet de rejoindre un salon vocale', // EXECUTEUR async execute(client, message, args) { const connection = await message.member.voice.channel.join(); connection.join() }, }; error:```diff
- message.member.voice.channel.join is not a function
v13 remove VoiceChannel#join and all other voice supports, use the joinVoiceChannel() in the new voice lib
okay thx
@carmine timber i still cant reproduce any of the errors raised in your pull request
what version of typescript are you using
can anyone please help me know how to make the bot join the voice channel. I tried this but it didn't work out:
const { joinVoiceChannel } = require("@discordjs/voice");
const vc = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
selfDeaf: true
})
console.log(vc)
await message.react(embedsetting.emojis.success)
.catch((err) => {});
how discord.js v13 new voice looks like ?
Does anyone know any other way I can voice receive cuz I don't understand the docs and don't have a example
i'm using these versions and still can't reproduce this error
does npm run build in the music-bot folder work for you
voice receive is coming soon
there's an open PR for it
finally hydrabolt respond to me
I will check that out, thanks <3
can you help me with this? @vocal valley sorry for the ping tho.!
joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
}),```
You can try this. `channel` here is
`voiceChannel`
when will be able to record audio
thanks it worked.
YW
how to install dev version of voice?
@vocal valley how would you use the voice-reciver im on that dev branch
It shows me the same error
Hydrabolt, he also got this error
I get this error when doing npm start
Strange enough on my repo which have the same function, ts doesnt bug me about it, though it is js file with jsconfig.json to typecheck my js files
I am talking with hydrabolt, I know how to solve this error. I have created a PR for this only. I need no suggestions.
const process = require("youtube-dl-exec").raw("youtubeurl", {
o: "-",
q: "",
f: "bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio",
r: "100K"
}, {
stdio: ["ignore", "pipe", "ignore"]
});
if(!process.stdout) return;
const stream = process.stdout;
process.once("spawn", () => {
demuxProbe(stream).then(probe => {
this.resource = createAudioResource(probe.stream, { inputType: probe.type });
this.play(); // internal funcs
}).catch(e => {
if(!process.killed) process.kill();
stream.resume();
});
});
Essentially the example code incorporated into my own audio controller
When I go to play the audioResource, I get the silence frames and nothing else. Either that or its playing nothing at all.
I've been scratching my head for hours and I've tried everything I could think of. I just need a nudge in the right direction.
Did you changed youtube-url with your url ??
Of course. This is just an example of what I have.
Just check first if you get process.stdout or not by console logging it.
Yep, I've got the socket connection, no errors, looks good
I've also already checked the output of demuxProbe() and then also the output of createAudioResource()
They both look alright to me
Then show me play() function code.
This looks good to me.
<audioPlayer>.play(<audioResource>);
Nothing special
To clarify - this worked fine with ytdl, except that every so often it would abort the stream for no reason
So I've moved to youtube-dl-exec and followed an example available in the @discordjs/voice repo
@bitter sky could you try replacing youtube-dl-exec with just regular youtube-dl with ChildProcess.spawn
Sure, just a moment
It's telling me I don't have sodium installed, although I do. I'm going to reinstall it and try again
I installed youtube-dl through python3-pip and spawn it with the same arguments, and I get the same result, but much quicker.
It joins then leaves the channel straight away.
I've had a look at probe.stream and it has a length of 0 @vocal valley
The process.stdout itself also has a length of 0
I'm pretty sure I'm spawning it properly
@bitter sky anything in stderr
?
stderr <Socket> length: 0
will message u later about it
my guess for now is to see if you can get ChildProcess.spawn to work outside of any voice code, e.g. can you spawn the process and then pipe stdout to a valid audio file?
If I run the youtube-dl command from my cli I can see the stream just fine. I'll try piping it to a file
Thanks for the help :)
I'll see what I can do
how to seek a song in v13
const ffmpeg_instance = new prism_media.FFmpeg({
args : ['-ss', '5000ms', '-accurate_seek' ,'-i', songurl, ...FFMPEG_OPUS_ARGUMENTS ]
})
let resource = createAudioResource(ffmpeg_instance, { inputType: StreamType.OggOpus , inlineVolume : true });
thatll seek 5 seconds into the stream
_ _
_ _
Following https://github.com/discordjs/voice/blob/main/examples/radio-bot/index.js
I see that there is:
function attachRecorder() {
player.play(
createAudioResource(
new prism.FFmpeg({
args: [
'-analyzeduration',
'0',
'-loglevel',
'0',
'-f',
'pulse',
'-i',
'pulse' === 'dshow' ? `audio=audio_hw_device_id` : 'audio_hw_device_id',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
],
}),
{
inputType: StreamType.OggOpus,
},
),
);
console.log('Attached recorder - ready to go!');
}
how do i define what song to play? with the above code snippet
@vocal valley Now merge the PR.
https://github.com/discordjs/voice/tree/main/examples/radio-bot#readme
You should first see what is actually a radio bot and how to configure it.
If you still want to play from a url, just replace next argument after -i with your url.
so "'pulse' === 'dshow' ? audio=audio_hw_device_id : 'audio_hw_device_id'," should be my URL?
Yes change that to your url.
Also remove -f and pulse from the args list
if i do "attachRecorder(songurl)"
could i do more than one song if i filter through songurl for where the url of the media is meant to be?
or would i have to make multiple players?
TypeError: adapterCreator is not a function
I have problem, my bot streaming music but after about 3 hours the streaming stopped.
what is 5_000
Use music-bot instead. Radio bot is meant to play same song on all guilds.
Show me the voice module version by npm list @discordjs/voice
Show me the code where you created resource.
5_000 = 5000 ms = 5 secs
help me please.
i want to streaming 24/7
thats the point
i want more than one option for radio but i want it to sync across all
its latest today only installed
Show me the code .
Then create audio source and player at start of the bot and then attach every voice connection in each guild.
For creating audio source though link see this :- https://github.com/discordjs/voice/issues/117#issuecomment-860081673
yes but do i need to make a new audio resource for every station?
Yes of course
fuckkk ok ok
const Discord = require("discord.js");
const fs = require('fs');
// eslint-disable-next-line no-undef
client.on('message', async message => {
// Join the same voice channel of the author of the message
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
}
});
// Create a dispatcher
connection.play('');
dispatcher.on('start', () => {
console.log('audio.mp3 is now playing!');
});
dispatcher.on('finish', () => {
console.log('audio.mp3 has finished playing!');
});
// Always remember to handle errors appropriately!
dispatcher.on('error', console.error);
dispatcher.pause();
dispatcher.resume();
// Set the volume to 25%
dispatcher.setVolume(0.25);
voiceChannel.leave();
any error?
@bronze swanhelp
2 Things :
-
This is channel for talking about new voice api, not old voice api. Talk here #archive-djs-v12-voice-deprecated
-
While sending code , add this :
```js
<your code here>
```
It looks like this :
<your code here>
What could be the causes of the Error: aborted, the connection between the AudioPlayer and the resource or an Ytdl error from downloading the video?
It happens randomly and it puts the player on Idle with in my case passes to the next music
Thats an ytdl error
var channel = message.channel
var resource = voiceclient.createAudioResource(ytdl('https://www.youtube.com/watch?v=26Ln8V6og-c', { filter : 'audioonly' } ))
var player = voiceclient.createAudioPlayer()
player.play(resource)
voiceclient.joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
}).subscribe()
TypeError: Cannot read property 'subscribe' of undefined
What would cause this?
I know joinVoiceChannel would be undefined but I dont see how
Thanks, I will reach out to their support
change that to .subscribe(player)
alrigfht thx
Error [VOICE_NOT_STAGE_CHANNEL]: You are only allowed to do this in stage channels.
This is definetley a stage channel
I've had this issue lately too, just had another look at ytdl's issues and found this
Haven't tested it yet but maybe it'll help. I'm using node 16 too
I will give it a shot, thnks
discord.js version ?
nope I put the wrong ID variable name
Ok 👍
I will try this: https://github.com/Hazmi35/jukebox/issues/552
Why don't you try youtube-dl method as mentioned in examples ??
Creating streams with ytdl-core has many issues.
I will give it a shot sometime, I already know how to use the Ytdl-core so I coded in that way
Nothing much differ actually
No, ytdl-core streams when not handled correctly can cause serious memory leaks, which might be a huge issue who is creating a music bot for many guilds.
I mean the method ytdl(url, args) same as youtube-dl(url,arg)
But youtube-dl requires much more coding initially than ytdl-core.
I'm even having issues with youtube-dl-exec
Including using the python binary for youtube-dl
Then you can go with FFMPEG method.
I still have to download the YouTube audio
What exactly could be the issue though?
With the connection aborting?
Who knows, maybe YouTube does some kind of check now that ytdl doesn't handle, or the node runtime, or the package itself
Aborting? So far, I dont have it issue, play fine for 4hrs+
No, In that method you just get youtube url (audio endpoint) from ytdl-core and then pass that to ffmpeg. Rest audio resource will handle correctly. You don't need to download youtube audio at all.
So how do we get the audio stream from a url
We can't play what we haven't got haha
We can play. Do you want code for ffmpeg method ??
I'm out and about right now and am behind on an important freelance project anyway, so I can't do too much in the short term. If you could DM me any resources though I'll check them out. I appreciate it
When will you get time to see that resources ??
I can have a quick look in a few hours but I've really got to make some progress on something else first
Ok, Let me send you
Thanks. It's not really a life or death issue anyway. Music streaming is a novelty
I know XD Hahah
It's Node 16 with something with Ytdl-core, after setting the js Ytdl(link, { filter: 'audioonly', quality: 'highestaudio', highWaterMark: 1048576 * 32 });
highWaterMark: 1048576 * 32 = which is (32 Mib) the issues stopped, it is running for 30 mins without any aborts if U don't want to use youtube-dl
That'd be so much simpler, thank you very much
@vocal valley May you consider my PR.
Just had a quick look, looks like a nice solution to be honest! I'll just try to think of some alternatives before settling on this
Thanks for the PRs
😄
Hi guys. I used the voice example Basic and music-bot and it does "work" for me. But sometimes player get Autopaused state and the only way around is a "needed" restart of the app to playing anything. I use this:
o: '-',
q: '',
f: 'bestaudio[ext=webm+acodec=opus+asr=44000]/bestaudio',
r: '64K',
}, { stdio: ['ignore', 'pipe', 'ignore'], maxBuffer : 3e9 });
if (!process.stdio) {
console.log('No readable stream');
return;
}
const stream = process.stdout;
const onError = (error: Error) => {
if (!process.killed) process.kill();
stream.resume();
console.log(error);
};
const resource = createAudioResource(stream, {
inputType: StreamType.Arbitrary,
});
this.player.play(resource);
this._PlayerEvents(this.player);
Output:
[DEBUG] PlayerState: playing -> idle
[DEBUG] PlayerState: buffering -> playing
[DEBUG] PlayerState: playing -> idle
[DEBUG] PlayerState: buffering -> playing
[DEBUG] PlayerState: playing -> idle
[DEBUG] PlayerState: buffering -> playing
... (up to work fine song by song)
[DEBUG] PlayerState: playing -> autopaused
[ERROR] Player <Autopaused> for +3 seconds```
Any idea?
Node v16.5.0
discord.js: 13.0.0-dev.02693bc02f45980d8165820a103220f0027b96b7
discordjs/voice: 0.5.3
Do you want player to be paused when there is no one in bot's voice channel ??
my problem is that during the reproduction of the music, the player some times goes into autopause state with ppl inside the channel with no commands given "just because"
Just add this code where you created the player :
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});
@carmine timber I've just tried this and I haven't had an issue yet. This works perfectly
I tried it before your solution just because it was so much simpler
ytdl-core has some memory leaks issues. If you don't care about that, then go ahead with ytdl-core.
I used ytdl-core-discord, not sure if there's any difference, but my process manager hasn't flagged it for using too much memory
No issue arises, when you play some song ( long duration one ) and then tries to skip that song. YTDL will continue playing that old song in background. This will result in a Memory Leak.
Ah, I can probably close the socket programmatically, plus I don't allow songs longer than 7 minutes or something
Thanks for your concern though
BTW, I have created a PR for that FFMPEG method to make it easy to use.
Creating multiple songs and then skipping songs will also result in memory leaks unless the ytdl-stream is closed perfectly.
I'll keep an eye on it, thanks
Ok 👍
I had a look at your PR. Looks awesome
Thanks.
@vocal valley Do I need to worry about codecov/patch and codecov/patch failing (while running checks) ??
@carmine timber, i figured that memory leak happens with youtube-dl-exec. After playing music for 2-3 hours simultaneously, the bot automatically restarts and logs that the memory usage was overlimit.
I’m using ytdl-core and seem to play songs in repeat for like 13 hours now.
Music total duration ??
I have tried 5-12 hours. All the same
ytdl-core has some memory leaks too.
the memory leaks are most likely with your own code or djs v12
i havent noticed any memory leaks in ytdl-core
Memory leaks occurs when you play a song ( of long duration ) with ytdl-core and then skip that song. If that stream is not handled correctly, It will continue to run in background and thus causing memory leaks
More info : https://github.com/discordjs/voice/discussions/123
Me too, but with the same code and with youtube-dl-exec, i faced memory leak.
so the memory leak is caused by your own code not handling the stream correctly.
Just visit the link and see the 2nd code. I did player.stop() function in new voice api (Which destroys audio resource) but IN reality, ytdl-core stream continues to run in background
so you should close the ytdl-core stream
That Just means create 2 different streams (One of ytdl-core and second of voice module ) and close both properly. 👏
tbh
in my own code i have 4 + the audio resource streams running simultaneously. And so i dont get memory leaks i have to close all of those
Experienced programmers knows about this but New programmers don't know about this and they start creating issues (Memory leaks) in djs-voice v12. Old voice module was also comparable to new voice module if you are experienced.
ytdl-core readme explicitly tells you to call stream.destroy() if u wish to abort the download
@fervent estuary Do you know why this happened ??
if the same error didnt occur with ytdl-core with the same code it would look like there is a memory leak in youtube-dl-exec
One bot can join only one voice channel right ?
in a server yes
thx
For past 2 days, RAM usage are the same even with how many hours I played song using youtube-exec-dl
Show us your code.
I think he copied paste my code before, which on track.js, some of the code make the buffersize going higher and higher. and than I realized about it and changed. That the bad idea if copy pasting others without knowing thing
Which part of your code makes buffersize go higher and higher ??
youtube-dl arguments
Oh okay
After the code changes, this is the value even after I played song 3hrs+, using ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB
Did you add more arguments in youtube-dl ?? that made memory usage so low.
nope.
I can do some endurance test to see it, play song on repeated mode for 8hrs+ like it 🤔 Maybe I see something interesting
what are the changes of this new voice system?
see pins
I know this isn't documented here, that's why I'm looking for help lol
you can simply say everything
What help exactly ??
wrong channel sorryl
#archive-djs-v12-voice-deprecated and #archive-voice at the same time lo
Looking back at the argument of the youtube-dl-exec, I changed the audio sampling rate to 44100, that should factor in the memory usage too? Other changes I don't think affect much like process.once('spawn',..) to process.on('spawn'...)
What type of AudioResource does this return?
return createAudioResource(createReadStream(audioFile), {
inputType: StreamType.OggOpus
});
That is the main reason 😄
I think the other reason might be I'm using the event method instead of the collection method. Collector method add listener everytime, while interactionCreate only use 1 listener for the music button/selection
Is it possible to turn the adapter.ts to .js using ES6 exports?
ye
Where can I find info about that?
i'm using https://extendsclass.com/typescript-to-javascript.html but the exports are not compatible. SyntaxError: The requested module './adapter.js' does not provide an export named 'createDiscordJSAdapter'
can you show the js code you got from that?
I'm importing it like this
import { createDiscordJSAdapter } from './adapter.js';
and using it in:
const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: createDiscordJSAdapter(channel), });

does it work if you use require() instead of import?
I have set in the package.json "type": "module" so require() won't work
https://nodejs.org/api/packages.html#packages_type
ic
if u replace exports.createDiscordJSAdapter = createDiscordJSAdapter; with export createDiscordJSAdapter; in the adapter file work?
ofc its a function so that wont work
on line 50 add export in front of the function declaration
same error
how are u exporting anything out from your js files?
export { function_name }
give that a shot in the adapter file
I just found out I'm using a different version of the adapter. If I use the one from pastebin, and leave it as it is, I get
Object.defineProperty(exports, "__esModule", { value: true });
^
ReferenceError: exports is not defined```
If I replace the last line with `export createDiscordJSAdapter;` I get
export createDiscordJSAdapter;
^^^^^^
SyntaxError: Unexpected token 'export'
now
export {createDiscordJSAdapter};
^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Duplicate export of 'createDiscordJSAdapter'
did u leave some of the other exports?
the code that u sent in pastebin is just compiled ts
it might be just easier if u manually removed all ts stuff from the file
yep, I forgot to delete the export from line 50. Now it's
Object.defineProperty(exports, "__esModule", { value: true });
^
ReferenceError: exports is not defined
thats just the problem of using compiled ts without actually having a ts project setup
Oh 😓
so id recommend that u just remove all the typescript stuff from the adapter file and use it like that
Can i play live stream’s with the new voice? Seems to stop automatically after 10s
yep, that worked. I deleted everything that was after ":" and anything in between <>
https://pastebin.com/QZ5ArSTD
👌
Why is new-voice written in ts? It is part of discord.JS so that's why I was wondering
ig ts was just preferrable for it
d.js is also getting a rewrite in ts
Cannot perform IP discovery - socket closed i am getting this error but the bot joins the vc. is there anything to worry?
How do i record audio from a voice channel
(if possible)
its possible. Not 100% sure of the state of support for it. Anyways there are no examples yet
Alright
Bump
Hi, I'm having an issue.
I just remade my v12 bot to v13, it works great but it sometimes when I want to play something it just fast joins and leaves and throws and error Error: Did not enter state ready within 20000ms
Do you have any suggestions to do? If you want the code I can provide it, but it is so long...
Error: getaddrinfo ENOTFOUND brazil5203.discord.media
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17)
Emitted 'error' event on VoiceConnection instance at:
at VoiceConnection.onNetworkingError (c:\Users\jpedr\Desktop\Visual Code\Node.js\Botter V2\node_modules\@discordjs\voice\dist\VoiceConnection.js:266:14)
at Networking.emit (node:events:394:28)
at Networking.onChildError (c:\Users\jpedr\Desktop\Visual Code\Node.js\Botter V2\node_modules\@discordjs\voice\dist\networking\Networking.js:147:14)
at VoiceWebSocket.emit (node:events:394:28)
at WebSocket.VoiceWebSocket.ws.onerror (c:\Users\jpedr\Desktop\Visual Code\Node.js\Botter V2\node_modules\@discordjs\voice\dist\networking\VoiceWebSocket.js:28:39)
at WebSocket.onError (c:\Users\jpedr\Desktop\Visual Code\Node.js\Botter V2\node_modules\ws\lib\event-target.js:140:16)
at WebSocket.emit (node:events:394:28)
at ClientRequest.<anonymous> (c:\Users\jpedr\Desktop\Visual Code\Node.js\Botter V2\node_modules\ws\lib\websocket.js:688:15)
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'brazil5203.discord.media'
}
Adding a connection.on('error', (err) => { function... }) should stop it? If yes, how should I handle the error?
For some reason there is a 5 second delay to play a file when my bot joins the voice channel. Does anyone know what could be the culprit? It was originally a one second delay.
Now the delay is massive, and occasionally the bot won't play any sound.
My code has remained the same. Maybe I'm getting rate limited?
Code please.
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
Im using youtube-dl
any reason? every thing work perfectley with ytdl
- What does the youtube-dl arguments look like? Have you monitor the RAM usage when with both ytdl and youtube-dl?
both were low usage < 100MB
can you show the youtube-dl argument then? Might able to help, might not
alright
url, "-f", "best[ext=mp4]"
does it have to do with "best[ext=mp4]"?
I'm guessing you using child process and not the youtube-dl-exec package? you need to activate the quiet mode iirc
wait a sec, im using a 3rd party wrapper
thank you 🙏
I was using a wrapper called youtube-dl-wrap
for the -f param try this bestaudio[ext=webm+acodec=opus+asr=44100]/best since discord use web opus or w/ever the name
alright thank you!
update: cpu usage spikes to 45 and crashes with this
then it says the same error message
url, "-f", "bestaudio[ext=webm+acodec=opus+asr=44100]/best", "-q", "", "-o","-" If I follow the wrapper format. The error is because youtube-dl crashes
it still spikes like that, and crashes
it looks like the wrapper uses child process
so its a youtube-dl problem?
It is to spawn youtube-dl bin. not really, I'm using it right now. Using this https://www.npmjs.com/package/youtube-dl-exec and example use it too
my RAM usage so far, 48min song
I would I setup the options with it?
yea.
This is snippet of mine, it uses the same principle of child process too
does it store the entire song in memory?
No it stores songs in parts in memory. Once old part is done playing, it is gone from memory.
ok thanks!
That CPU hike is only when you initiated youtube-dl. On rest of playback, CPU usage is none (almost).
yea got it working!
😄
thanks! Still have no clue what was wrong i just switch my wrapper to youtube-dl-exec and it started working
Congrat and do mind checking RAM usage time to time
@vocal valley Found any alternatives ??
To what 👀
PR, FFMPEG
Have not had chance to look at it yet, working during the week
Ok
Will only be able to have a proper look next week unfortunately
No problem 👍
I have a resource that plays for a certain amount of time but usually not finishes. Then I play another resource via my audio player, do I need to get rid of my old resource that isn't played fully?
You need to destroy it so as to prevent memory leaks.
I updated discordjs to latest dev yesterday. Maybe after then, i can’t play music in multiple server’s at the same time. If i play on one server, the song starts without any issue. But if i try to play song in another server at the same time, the bot doesn’t join the vc and only queues the song. Any idea why this is happening?
thanks
Is that your own bot?
I own it, but the music system i took from someone else’s player.
your problem sounds like that the system doesn't use multiple audio players
It worked on multiple servers without any issue somedays ago
and you were on v13 that time?
Nothing major has changed after then. And, i updated v13 version yesterday.
Yep
huh, sadly I think I cannot help you then shrug
Hm, does the latest v13 changes interaction.guildID to interaction.guildId?
yep
all ID are now Id
Could that be the culprit?
probably, i think this has happened to a few people 😅
Hmm. Just to be clear, i’m on this version discord.js@13.0.0-dev.4886ae2.1627171445. Is it the latest dev version?
Yep, that fixed the issue.
Like I said many time, dont just copy, learn js. even the youtube-dl issue is because you copy paste
I’m learning js and i usually do that by looking into other’s code’s then finding out what the code does. I know i still know a little about js, but i’m trying to learn.
And for your information, i’m not stuck after your repo was hidden. I changed things to play 12 hour+ videos. And have playlist support, loop commands added etc. Trying to add more. I just can’t learn in the normal way. Sorry to copy your codes
Does the new voice can play livestreams properly?
Can’t i do it with ytdl-core? The problem is, livestreams play for 10-15s and then stops automatically.
VSCode can't read the types from tiny-typed-emitter. Can I fix this somehow or do I have to wait for a @discordjs/voice update
discordjs voice version ??
0.5.5
Restart TypeScript :
-
cmd+shift+P or ctrl+shift+P brings up command bar
-
Type restart and choose this option.
https://i.stack.imgur.com/zRhGr.png
Thank you, it worked. But it's weird: i just started VSCode a little while ago
.
Go to their discord server? I saw the api, should be able to? But i never tried, it not lib related at this point
Apparently it was my slow internet connection that was causing the delay. The bot was indeed playing the audio, my connection was just so bad it was delayed.
I’m already trying on their server, no fix until now. Let’s see if they can suggest any possible fix.
Hi, I'm having an issue.
I just remade my v12 bot to v13, it works great but if I want to play something it just fast joins and leaves and throws and error Error: Did not enter state ready within 20000ms
It make that every "first" play, cuz the second works great
Do you have any suggestions to do? If you want the code I can provide it, but it is so long...
what could be throwing this error?
Error: Did not enter state ready within 30000ms
at Timeout.<anonymous> (/home/ubuntu/bot-discord-js-v13/node_modules/@discordjs/voice/dist/util/entersState.js:17:49)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
is the bot trying to connect to a voice channel it doesn't have permission to talk in?
How do i see if a member is in a voice channel...? message.member.voice.channel keeps returning that im not in one.
Do i need to install the voice library?
For me?
const voice_channel = message.member.voice.channel;```
```js
const connection = joinVoiceChannel({
channelId: voice_channel.id,
guildId: voice_channel.guild.id,
adapterCreator: voice_channel.guild.voiceAdapterCreator,
});
connection.on(VoiceConnectionStatus.Ready, async () => {
// not firing
}```
Why is that event not firing...?
maybe replace
connection.on(VoiceConnectionStatus.Ready, async () => {
}
with
connection.on('stateChange', async (_, newState) => {
if (newState.status == VoiceConnectionStatus.Ready) {
/// ...
}
}
I was following the guide here: https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#playing-audio
but if it doesnt work try this, it makes the same thing
Error: Did not enter state ready within 30000ms
at Timeout.<anonymous> (/home/container/node_modules/@discordjs/voice/dist/util/entersState.js:17:49)```
Why? I'm running it on a server and the bot responds, but its not entering the ready state..?
Maybe Intents or maybe your internet connection or maybe your code has errors.
Or didn’t enable the GUILD_VOICE_STATES intent
@subtle granite
hey
can i get some examples of how voice works
The examples you can find in the git for voice are quite comprehensive
do i need to make an adapter to play sounds and join vcs or is it optional?
If you're using Discord.js v13 dev, it comes with its own adapters built in. If using some other lib or <= v12, yes
ok so i m using the dev built that means i dont need one
Yes. Just follow the above link
ok how do i start with joining voice channels and also why did discord.js make a sperate module
It will be merged when v13 releases
https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#creation = Joining VC
There are no other modular voice libs and baking voice support into the library increases lib size even if the user doesn't want voice support
if they r making a sperate lib, they should include some thing like playing music from yt and all
They do
really?
scroll down to the optional deps
nice, ty discord.js
also one more thing, i cant get the property voice of GuildMember
GuildMember.voice still exists in master
Make sure you're actually trying to access a GuildMember
wait lemme show you my code
import Discord from 'discord.js'
import Voice from '@discordjs/voice'
export default {
run: async (interaction: Discord.CommandInteraction) => {
if (interaction.inGuild()) {
Voice.joinVoiceChannel({
channelId: '859635708020523022',
guildId: '859635708020523018',
adapterCreator: interaction.guild.voiceAdapterCreator
})
}
}
}```
Error ??
property voice does not exist on GuildMember
Which part of code ?
whereever i try to put it
I can't see any code which tells me that you need GuildMember.
Show me what code your are putting.
nvm i m doing it the old fashioned way
Ok
can u tell what is the method of playing audio
You need 3 lines of code :
-
Create a AudioResource first [https://deploy-preview-595--discordjs-guide.netlify.app/voice/audio-resources.html#creation]
-
Create a AudioPlayer[https://deploy-preview-595--discordjs-guide.netlify.app/voice/audio-player.html#creation]
-
Playing the resource and attaching it to voice [https://deploy-preview-595--discordjs-guide.netlify.app/voice/audio-player.html#playing-audio]
import Discord from 'discord.js'
import Voice from '@discordjs/voice'
export default {
run: async (interaction: Discord.CommandInteraction) => {
let connection = Voice.joinVoiceChannel({
channelId: interaction.guild.members.cache.get(interaction.member.user.id).voice.channel.id,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
})
let resource = Voice.createAudioResource('C:\Users\hp\musiz\js\routes\bot_sounds_airhorn_airhorn_default.ogg')
let player = Voice.createAudioPlayer()
player.play(resource)
connection.subscribe(player)
}
}```
this code is not working, does not give error too
Your location to ogg is wrong
You need double back slashes in windows
Path = C:\\Users\\hp\\musiz\\js\\routes\\bot_sounds_airhorn_airhorn_default.ogg
oh
still not working
interaction.guild.members.cache.get(interaction.member.user.id).voice.channel.id you can access member directly from interaction become interaction.member.voice.channel.id
thats not actually working dats why i did this, its just as fast as ur method
lol? That is how I do, and working. Though, what is really not working again?
its doing everything except for playing audio
import Discord from 'discord.js'
import Voice from '@discordjs/voice'
export default {
run: async (interaction: Discord.CommandInteraction) => {
let connection = Voice.joinVoiceChannel({
channelId: interaction.guild.members.cache.get(interaction.member.user.id).voice.channel.id,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
})
let resource = Voice.createAudioResource('C:\\Users\\hp\\musiz\\js\\routes\\bot_sounds_airhorn_airhorn_default.ogg')
let player = Voice.createAudioPlayer()
player.play(resource)
connection.subscribe(player)
interaction.reply({
content: 'hi'
})
}
}```
here is my code till now, which works till interaction.reply except it does not play the file
Do it join voice channel ??
yesh
Hi @spare wave,
Sorry to bother but i’m stuck somewhere and createAudioResource function says no stdout. I know it’s not good to ask for code but can you please send the createAudioResource function of the Track.js file?
Can you create a separate file and add this code there and run and show me console.log:
const { generateDependencyReport } = require('@discordjs/voice');
console.log(generateDependencyReport());
ok
Core Dependencies
- @discordjs/voice: 0.5.5
- prism-media: 1.3.1
Opus Libraries
- @discordjs/opus: 0.4.0
- opusscript: 0.0.8
Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: 1.0.3
FFmpeg
- version: 4.3.2-2021-02-27-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
try update your discordjs/opus
Yes
"@discordjs/opus": "^0.5.3", latest now is 0.5.3
That's what I was going to say XD
still not working
@empty torrent on here js if (!process.stdout) { reject(new Error('No readable stream')); return; } change the process.stdout to process.stdio
Do this once again
Okay, let me try that.
You mean js if (!process.stdio) { reject(new Error('No readable stream')); return; }
yes. try and see
Didn’t work. Still same.
What track you playing?
createAudioResource() {
return new Promise((resolve, reject) => {
const process = ytdl.raw(this.url, {
o: '-',
q: '',
f: 'bestaudio[ext=webm+acodec=opus+asr=44100]/best',
r: '200K',
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0',
geoBypass: '',
}, { stdio:['ignore', 'pipe', 'ignore'], maxBuffer: 3e6 });
if (!process.stdout) {
reject(new Error('No readable stream'));
return;
}
const stream = process.stdout;
const onError = (error) => {
if (!process.killed) {process.kill();}
stream.resume();
reject(error);
};
process
.on('spawn', () => {
audio.demuxProbe(stream)
.then((probe) => resolve(audio.createAudioResource(probe.stream, { metadata: this, inputType: probe.type })))
.catch(onError);
});
});
}``` this basically mine, if that still not working, I have no idea
Why do you need userAgent ??
for science 
🤣
can remove it, it jsut some silly stuff I meddle around
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.5.5
- prism-media: 1.3.1
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: 0.0.8
Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: 1.0.3
FFmpeg
- version: 4.3.2-2021-02-27-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------```
Let me try that. No track works
One last question, can you play livestream with that function?
you can try. I have no idea because I don't play live audio, and not planning to
Can you create a separate file and add this code there and run and show me console.log:
const fs = require('fs')
console.log(fs.existsSync('C:\\Users\\hp\\musiz\\js\\routes\\bot_sounds_airhorn_airhorn_default.ogg'))
Hmm. Seems i can’t with youtube-dl-exec. Thank you so much though!
Irrc: There is no live stream format included in the github example's code, I had to add for my own.
f: 'bestaudio...
u can go check youtube-dl docs or smth
Oh, okay. I’m on it. Thank you
true
what is wrong with my djs voice
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.5.5
- prism-media: 1.3.1
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found
Encryption Libraries
- sodium: not found
- libsodium-wrappers: not found
- tweetnacl: not found
FFmpeg
- not found
--------------------------------------------------
Error: FFmpeg/avconv not found!
how to fix it?
npm install ?
npm install ffmpeg-static
BTW, you also need to install Encryption libraries also
how?
npm install ?
npm install <Encryption-library name (any one)>
thanks, it's work!
witch one is the best?
best is sodium, but hard to install. so go for libsodium if you struggle installing sodium
Docs are also misleading 
https://deploy-preview-595--discordjs-guide.netlify.app/voice/audio-resources.html#creation
When will recording come out? and how can i install / use the dev branch version rn.
See pins at #djs-help-v14 for installation of djs v13
dev voice branch
There is nothing like dev voice branch.
Voice module is a optional right now but it will be merged once v13 is released.
So you need to download voice module separately
i am trying to join my bot to a stage channel but it joins in the audience section. can I directly move it to the speaker section?
are you sure that you put the stage channel id?
yea. btw i am using a testing bot which is not verified is that a problem?
Ohhh, I'm so stupid. Thanks!
When my bot joins a voice channel, it shows itself as muted. Any way to hide this?
is it server muted or just muted?
It shows the headphone symbol. It sends the audio but I would like to not have the headphones symbol.
By default the bot self deafens, it's not muted. It's fine
yes, usually bots don't need to hear audio
yes, but I don't like the symbol there, looks odd
It's common among bots
if you are making a usual bot it should be fine, otherwise, just undeafen
How do I undeaf it? I mean, I don't need to, but I'd like to.
oh, found it c:
Hey I created a radio bot, which has a single audio resource per shard/cluster and every server subscribes to the same resource but still the bot is using so much ram and cpu. ```
CPU: 6Vcore
RAM: 16GB
if you need any additional details let me know
Do you have single player running or multiple players running ??
Every client has its own player handler class
And I have 34 shards and 6 clusters
That is the main reason for lot of memory.
For a radio bot, you need only one player (per shard) that is going to play in all connections.
So what would be the best way to do it?
Create player per shard and Let the resource play and whenever someone wants to hear that music just create a voice connection and subscribe the player to that connection.
So in this way, you use less resources
Isn't my player handler class doing thet?
You are creating a audio player for every client.
So, there will be a lot of audio players running simultaneously and using a lot of memory.
So I remove the audio player from player handler class but where should I move it to Ready Event?
No create a player when main.js file is executed and play the resource on ready event like this :
https://github.com/discordjs/voice/blob/main/examples/radio-bot/index.js
Hmm
Alright thanks. I'll look into it
Having trouble installing the package, I keep getting this error \node_modules\@discordjs\voice\dist\index.js'. Please verify that the package.json has a valid "main" entry Followed the guide that's pinned.
Create a new folder and then open cmd and type there npm init -y and then install djs voice module
Yep, that worked. Thanks!
How can i get the playback time?
hey, can i directly play music from yt, spotify and soundcloud using their urls or do i need to install packages
You can't play from Spotify,
so from yt and soundcloud i can play? without ytdl?
Nope
You need a Downloader for playing from youtube
Yes you can play without ytdl also, if you manage to extract audio endpoint url from their sites by yourself.
Downloader for playing audio ?? 
Ytdl downloads the audio then it's get streamed to discord? Or you can create pipeline or something and stream to discord
YTDL do 2 things :
-
Uses some mechanism (That I know, but you need to explore yourself) to extract a audio endpoint url which looks something like this [https://www.shorturl.at/bvGP4 ( A shortened URL but long url is the one which we extract audio endpoint url)]
-
Then it uses this url to create a Readable NodeJS Stream (https://nodejs.org/api/stream.html) and just gives us output.
Now voice module also creates stream from a url or file path and then pass that to audio player for playing that audio. [ Voice Module can also accept Readable NodeJS Streams also ]
In this whole process, nothing is actually downloaded. It is just an example of NodeJS Stream functionality. You need to understand how nodeJS Streams actually work to understand this whole process
when i am using my ts code and running it with ts-node, it says that all client properties are possibly null, how to fiz
Do you have typescript installed ??
Oh I see
yesh
Type tsc --version and show me the version.
4.3.5
Now do this : tsc <your ts file>
This will convert your ts file to js file and then run that js file with node command
but i dont want dat to happen
cant i just run the ts file
All ts files are converted to js format. Even discord js voice module which is made in TS are also converted to js once you install the module
ohk so will my types still be there?
typing are only used for developing, in the JS file there will be not types, because Javascript doesn't understand them and they are not needed
you can use tools like ts-node / ts-node-dev which will run the ts files and auto restart the script if you made changes
(I am using this)
how do you make a bot join a voice channel and deafen
In the joinConfig set selfDeaf to true
defaults to true anyway lol
well from some reason I get an error of the bot not joining the voice channel
Might wanna share some code with the error
60 - 80 %, it will be due to Guild_voice_states intents not added in client.
this is wht I got for right now
const client = new Client({
disableMentions: "everyone",
restTimeOffset: 0,
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS]
});
then my error Is I get this
TypeError: voiceChannel.join is not a function
at Object.executeSlash (C:\Users\wow\Desktop\BrettFX Bot\commands\play.js:372:58)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
and this is on line 371 to line 378
if(interaction.member.permissions.has("MANAGE_MESSAGES")) {
queueConstruct.connection = await voiceChannel.join();
queueConstruct.connection.voice.setSelfDeaf(true);
play(queueConstruct.songs[0], interaction, voiceChannel);
}
?
Sir You can't do that in djs developer branch.
You need to install this : https://deploy-preview-595--discordjs-guide.netlify.app/voice/
And then to connect : https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#creation
Ok I installed it now what
Make a new js file and run this code there :
const { generateDependencyReport } = require('@discordjs/voice');
console.log(generateDependencyReport());
what is that gonna do
I dont recommend ts-node in production BTW, better to use typescript compiler
You can use tsc --watch BTW
true
is there any option to set audio bitrate? like in createAudioResource, demuxProbe, createAudioPlayer or can I somehow set it on audioplayer?
Is there a way i could pause and resume the player?
You can pass param abr (Audio bitrate) along with the value to f option if you are using youtube-dl-exec to prepare the resource.
👍
and how would i check if the song is already paused and such? Intellisense is a pain rn and not working, cant see any of the methods 
thx, but I actually dont use youtube dl
I’m not sure if there is any function for that. But you can surely create an isPaused variable and assign boolean to it after pausing the player. And check for it always with a condition. Sorry for the bad English. Here is an example check -
//Following the example music bot
//In subscription.js after this.queue
this.isPaused = false;
//in your pause command (assuming ‘subscription’ is your get variable for each guilds playlist
if(subscription.isPaused) {
interaction.reply('The player is already paused');
} else {
subscription.isPaused = true;
interaction.reply('Player paused successfully!')
}```
Same for the unpause/resume command. Sorry for the bad English
Whatever you use, i guess there is definitely an option there.
I was hoping I didn't have to do something like this. Thanks though 👍
I’m not sure, maybe there is a way. Let someone else come to answer that.
Thank you
, so generous
ytdl-core, i asked a while ago on their discord and they said no, so I used an option and dispatcher but it is not there any more
Hmm. Maybe someone else can help on that.
Is there anything important i should do to play music in stage channel?
Currently the bot joins as an audience only.
music:67:27 createAudioResource
"@discordjs/voice": "^0.5.5"
Like the error mentioned, you need to install this
I have it installed
npm ls @discordjs/opus? If it exist , no idea. why it still not detecting
Ill try reinstall all deps
Might be clash with the discord-mentions dep
I uninstalled it and it somehow works

Anyone?
You can use
const { AudioPlayerStatus } = require('@discordjs/voice')
var state = <AudioPlayer>.state()
if(state === AudioPlayerStatus.Paused || state === AudioPlayerStatus.AutoPaused) {
//Player is paused
}
thanks!
First read docs completely and then suggest people.
BTW do you need this above code only ??
wdym
yeah, that's all I need.
You told that you don't want to do that. So I assumed you don't want this either
No I meant like having to create an explicitly assigned variable if the player is paused then set it to a condition and such. That works perfectly
Okay 👍
For setting audio bitrate, you need to create a FFMPEG instance and then set audio bitrate there and then pass it to FFMPEG.
can someone show me a just quick example on how to join/leave voice channels with the new system? my old method obviously doesnt work anymore, so i would like to see how its performed now
Sir You can't do that in djs developer branch.
You need to install this : https://deploy-preview-595--discordjs-guide.netlify.app/voice/
And then to connect : https://deploy-preview-595--discordjs-guide.netlify.app/voice/voice-connections.html#creation
how to check if a member is in a voice channel or not?
<Guild>.me.member.voice?.channel
why does it doing this?
i am trying basic script
What is the error?
that is so complicated
TypeError: adapterCreator is not a function
at new VoiceConnection (F:\Rami\node_modules\@discordjs\voice\dist\VoiceConnection.js:74:25)
at Object.createVoiceConnection (F:\Rami\node_modules\@discordjs\voice\dist\VoiceConnection.js:480:29)
at Object.joinVoiceChannel (F:\Rami\node_modules\@discordjs\voice\dist\joinVoiceChannel.js:18:30)
at F:\Rami\node_modules\discord-player-music\src\Player.js:532:30
at new Promise (<anonymous>)
at MusicPlayer.joinVoiceChannel (F:\Rami\node_modules\discord-player-music\src\Player.js:525:16)
at Object.run (F:\Rami\cmds\slash\join.js:31:23)
at run (F:\Rami\events\interactionCreate.js:20:17)
at Rami.emit (events.js:315:20)
at InteractionCreateAction.handle (F:\Rami\node_modules\discord.js\src\client\actions\InteractionCreate.js:51:12)
Add this in <Voice>.joinVoiceChannel() adapterCreator: channel.guild.voiceAdapterCreator?
Either you need to update discord.js dev branch or update @discordjs/voice module.
Will be making this process easy soon. Wait for discord.js update.
dgram.js:897
throw new ERR_SOCKET_DGRAM_NOT_RUNNING();
^
Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
at healthCheck (dgram.js:897:11)
at Socket.send (dgram.js:622:3)
at VoiceUDPSocket.send (/root/voice/node_modules/@discordjs/voice/dist/networking/VoiceUDPSocket.js:90:28)
at VoiceUDPSocket.keepAlive (/root/voice/node_modules/@discordjs/voice/dist/networking/VoiceUDPSocket.js:74:14)
at Immediate._onImmediate (/root/voice/node_modules/@discordjs/voice/dist/networking/VoiceUDPSocket.js:42:33)
at processImmediate (internal/timers.js:461:21) {
code: 'ERR_SOCKET_DGRAM_NOT_RUNNING'
}```
How I can fix this error?
Maybe restart the bot
Strange, but I don't want to play anything. Enters and immediately exits the voice channel.
let res = DiscordVoice.createAudioResource(song.url);
this.player.play(res);
Do i need both djs opus and djs voice for a bot to join and do some stuff in vc?
Or i only need voice?
Both along with one encryption library
If you don't want to play, then why are you running command this.player.play () ??
It enters and immediately exits that means something is wrong. Show me your intents .
['GUILDS','GUILD_MEMBERS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'GUILD_PRESENCES', 'GUILD_VOICE_STATES']
I need to play a song, but the bot doesn't want to do it.
@carmine timber
Information update: the bot enters the voice channel, writes that the song is playing, but nothing is playing.
Give me song url
You can't play youtube songs directly.
You need a module for that
Ytdl-core?
Yes
play(guild, song) {
return new Promise(async (resolve, reject) => {
const serverQueue = await this.queue.get(guild.id);
try {
let stream = await this.utils.createStream(guild);
let res = DiscordVoice.createAudioResource(song.url)
this.player.play(res)
let connection = DiscordVoice.getVoiceConnection(guild.id);
connection.subscribe(this.player)
this.player.on("error", error => {
return this.emit('playerError', { textChannel: song.textChannel, requested: song.requestedBy, method: 'play', error: error });
});
//dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
this.emit('playingSong', this.queue.get(guild.id));
}catch(error){
return this.emit('playerError', { textChannel: song.textChannel, requested: song.requestedBy, method: 'play', error: error });
}
})
}
P.S. Don't throw stones, the code is not ready =)
Can you console.log(song.url) and tell me the exact url ??
I already threw.
I already told that You can't play youtube songs directly
You need a module (ytdl-core) for that.
let res = DiscordVoice.createAudioResource(ytdl(song.url))?
Yes, try that
The music starts playing, but most likely the filter system will not work.
What filter system ??
!filter 3D
Then you need to pass FFMPEG instance (with filter arguments ) to createAudioResource
This code not worked:
let res = DiscordVoice.createAudioResource(ytdl(song.url, {
opusEncoded: true,
filter: 'audioonly',
quality: 'highestaudio',
highWaterMark: 1 << 25,
encoderArgs,
dlChunkSize: 0
}))
how can i play spotify songs with discord.js voice
you cant...
get spotify meta data, search on youtube
You can't directly play song through spotify but can play indirectly ^^.
let connection = await joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: member.guild.id,
adapterCreator: member.guild.voiceAdapterCreator,
selfDeaf: true
});
let stream = await ytdl(`https://www.youtube.com/watch?v=${video.id}`);
connection
.subscribe(createAudioResource(stream))
Error:
TypeError: player.subscribe is not a function
help please
connection.subscribe(), no player
seems ur using player.subscribe somewhere else
also u r using connection to subscribe an audio resource, should be instead using a player to play
let player = createAudioPlayer();
player.play(createAudioResource(stream));
connection
.subscribe(player)
working, thx
How can I detect when the music stops + how change volume?
in djs v12 connection.play(stream).on("finish")
the player switches into an idle state if and only if the music stops so you can add a listener listened for AudioPlayerStatus.Idle event
and idk how to change volume, maybe the doc has it
using which lib?
hey i m having trouble in getting my bot to play songs from yt urls
can someone help, i have the intents too
const Discord = require('discord.js')
const Voice = require('@discordjs/voice')
const ytdl = require('ytdl-core')
const Yt = require('youtube-sr')
module.exports = {
name: 'play',
execute: async (interaction = new Discord.CommandInteraction()) => {
if (!interaction.member.voice.channel) return interaction.reply('Join vc')
let channel = interaction.guild.channels.cache.get(interaction.member.voice.channel.id)
if (!channel.permissionsFor(interaction.applicationId).toArray().includes('CONNECT' && 'SPEAK')) return interaction.reply('Hello')
else try {
let connection = Voice.joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
})
let video = (await Yt.YouTube.search('rickroll'))[0]
let resource = Voice.createAudioResource(ytdl(video.url))
let player = Voice.createAudioPlayer()
player.play(resource)
connection.subscribe(player)
} catch(e) {
console.log(e)
}
}
}``` here is my code
nvm i fixed it
anyways how do i set the volume of the player
HELLO GUYZ
I NEED HELP SO BAD MY BOT NOT WORKING WHEN I INSETALL @DISCORDJS/VOICE IT SHOW THIS ERROR TypeError: adapterCreator is not a functio
check out pins -> guide -> voice connections
How can I get the voice connection if the bot connected to the voice channel? [discord.js v12]
P.S. I know it's not there, sorry.
wdym?
The typing error for adapterCreator back again, @discordjs/voice v0.5.5, "discord.js": "^13.0.0-dev.t1627732975.331a9d3",
It has a temporary fix:
Go to discord.js --> typings --> index.d.ts
Add this line at top import { DiscordGatewayAdapterCreator } from '@discordjs/voice'
And then search this line :
public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
Change that to :
public readonly voiceAdapterCreator: DiscordGatewayAdapterCreator;
my fix // @ts-expect-error 
Turn out some of the command resolver broken too. welp, revert back to old commit
Error: Did not enter state ready within 30000ms
This happens when it tries to connect to a channel it doesn't have permission to join. How would I handle this?
Check if ur bot has permissions to join
¯_(ツ)_/¯
something along the lines of newState.channel.joinable()
Yeh