Discord.js: Audio not playing

Created on 1 Dec 2018  Â·  17Comments  Â·  Source: discordjs/discord.js

I am trying to make a music bot using node-opus instead of opusscript and I keep getting a TypeError.
Here's the play command: -

let voice_channel = message.member.voiceChannel;
let connection = await voice_channel.join()
const dispatcher = connection.playStream(ytdl(url))
            .on("end",()=>{
                console.log("Music Ended")
                voice_channel.leave()
            })
            .on("error",error=>{console.error(error)});

And I keep getting this error: -

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: connection.playStream is not a function

  • discord.js version: 11.4.2
  • Node.js version 8.9.4
  • Operating System: Windows 10 Pro
  • This issue is not actually very important but it would be great if I could solve it.
voice bug

All 17 comments

What happened to all of this:

Please describe the problem you are having in as much detail as possible:

Include a reproducible code sample here, if possible:


// Place your code here

Further details:

  • discord.js version:
  • Node.js version:
  • Operating system:
  • Priority this issue should have – please be realistic and elaborate if possible:
  • [ ] I have also tested the issue on latest master, commit hash:

Would be nice if you would actually fill this out.

@iCrawl I filled the details that I know about. Please let me know if you want to know anything else.

Are you sure you're actually on 11.4.2 and not using the master branch?

@amishshah I am on 11.4.2 and also using the master branch. I'm sure.

You cannot use two versions of a library at the same time, you either use 11.4.2 or you use master.

Can you tell us what is the output for this, please? npm ls discord.js

@kyranet I did npm ls discord.js
and this was the output: -
`-- [email protected]

@kyranet I did npm ls discord.js
and this was the output: -
`-- [email protected]

You're currently using stable version if the output is not incorrect.
Few methods are different in master...
Master: <Connection>.play()
Stable: <Connection>.playStream()

@boltxyz I've tried both after following the steps in this video - https://youtu.be/4LmY8VzUTBU
Nothing is working. I cross checked thrice. Except it's giving me the error.

I really have no idea how this has happened, are you using custom structures at all? Also, could you try altering your code to read like this:

...
let connection = await voice_channel.join()
console.log(connection.playStream);
console.log(connection.play);
const dispatcher = connection.playStream(ytdl(url));
...

It's for my own peace of mind, if you could send me the output of the console.logs then I'll be able to be sure whether or not you're actually using 11.4.x

@amishshah I did what you asked ( btw I also understood I have to use play not playStream() )
Here's what happened


M:\Trendy-Music>node index
Ready Now
undefined
[Function: play]

Although the bot is now joining and discord shows that it's actually speaking, I hear no sounds.

Ok at least there's some progress, could you add:

client.on('debug', console.log)

And send me the output from the logs? You may want to redact sensitive information such as your IP address from the log.

Also, could you send me your current code just to make sure there's nothing wrong there?

@amishshah here's what happened

Authenticating using token XXX
Using gateway wss://gateway.discord.gg/
Spawning 1 shards
[Shard 0] Connecting to wss://gateway.discord.gg/
[Shard 0] Connected to the gateway
[Shard 0] Setting a heartbeat interval for 41250ms
[Shard 0] Identifying as a new session
[Shard 0] READY gateway-prd-main-rp1n -> discord-sessions-prd-1-5 | Session 3a97797ff342b247b475f39f3c14643a
[Shard 0] Sending a heartbeat
Ready Now
[Shard 0] Heartbeat acknowledged, latency of 18427ms
(node:8856) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'permissionsFor' of null
(node:8856) [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.
[Shard 0] Sending a heartbeat
[Shard 0] Heartbeat acknowledged, latency of 2404ms
[VOICE (436813926735413248:2)]: Sending voice state update (queue length is 0): {"guild_id":"436813926735413248","channel_id":"436813926735413252","self_mute":false,"self_deaf":false}
[VOICE] received voice state update: {"member":{"user":{"username":"Trendy","id":"442661706083205140","discriminator":"9680","bot":true,"avatar":"a62cae6b27aa9cbe84545cd803d4e82a"},"roles":["442681678742159361"],"mute":false,"joined_at":"2018-05-06T13:38:56.838000+00:00","deaf":false},"user_id":"442661706083205140","suppress":false,"session_id":"3a97797ff342b247b475f39f3c14643a","self_video":false,"self_mute":false,"self_deaf":false,"mute":false,"guild_id":"436813926735413248","deaf":false,"channel_id":"436813926735413252"}
[VOICE] connection? true, 436813926735413248 3a97797ff342b247b475f39f3c14643a 436813926735413252
[VOICE (436813926735413248:2)]: Setting sessionID 3a97797ff342b247b475f39f3c14643a (stored as "undefined")
[VOICE (436813926735413248:2)]: Authenticated with sessionID 3a97797ff342b247b475f39f3c14643a
[VOICE] received voice server: {"t":"VOICE_SERVER_UPDATE","s":4700,"op":0,"d":{"token":"3d8773b9ab56a953","guild_id":"436813926735413248","endpoint":"us-central161.discord.gg:80"}}
[VOICE] voiceServer guild: 436813926735413248 token: 3d8773b9ab56a953 endpoint: us-central161.discord.gg:80
[VOICE (436813926735413248:2)]: Token "3d8773b9ab56a953" and endpoint "us-central161.discord.gg:80"
[VOICE (436813926735413248:2)]: Endpoint resolved as us-central161.discord.gg
[VOICE (436813926735413248:2)]: Authenticated with sessionID 3a97797ff342b247b475f39f3c14643a
[VOICE (436813926735413248:1)]: Connect triggered
[VOICE (436813926735413248:1)]: [WS] connect requested
[VOICE (436813926735413248:1)]: [WS] connecting, 1 attempts, wss://us-central161.discord.gg/?v=4&encoding=json
[VOICE (436813926735413248:1)]: [WS] opened at gateway us-central161.discord.gg
[VOICE (436813926735413248:1)]: [WS] >> {"op":0,"d":{"server_id":"436813926735413248","user_id":"442661706083205140","token":"3d8773b9ab56a953","session_id":"3a97797ff342b247b475f39f3c14643a"}}
[VOICE (436813926735413248:1)]: [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750}}
[VOICE (436813926735413248:1)]: [WS] << {"op":2,"d":{"ssrc":4,"port":53311,"modes":["xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"172.107.196.238"}}
[VOICE (436813926735413248:1)]: Selecting the xsalsa20_poly1305_lite mode
[VOICE (436813926735413248:1)]: [UDP] created socket
[VOICE (436813926735413248:1)]: Sending IP discovery packet: [0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[VOICE (436813926735413248:1)]: Successfully sent IP discovery packet
[VOICE (436813926735413248:1)]: [UDP] message: [4,0,0,0,53,57,46,57,52,46,54,46,50,52,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,232,124] (   59.94.6.244                                                     �|)
[VOICE (436813926735413248:1)]: [WS] >> {"op":1,"d":{"protocol":"udp","data":{"address":"59.94.6.244","port":31976,"mode":"xsalsa20_poly1305_lite"}}}
[VOICE (436813926735413248:1)]: [UDP] << {"address":"59.94.6.244","port":31976}
[VOICE (436813926735413248:1)]: [WS] << {"op":4,"d":{"video_codec":"VP8","secret_key":[57,220,1,240,73,67,87,121,228,71,2,35,199,98,67,85,111,226,205,45,194,82,168,250,49,209,234,35,252,125,80,19],"mode":"xsalsa20_poly1305_lite","media_session_id":"084f8785151f3411ca8b0352c82c3fc1","audio_codec":"opus"}}
[VOICE (436813926735413248:0)]: [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":4}}
[VOICE (436813926735413248:0)]: [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":4}}
[VOICE (436813926735413248:0)]: Ready with authentication details: {"ssrc":4,"port":53311,"modes":["xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"172.107.196.238","mode":"xsalsa20_poly1305_lite","video_codec":"VP8","secret_key":{"0":57,"1":220,"2":1,"3":240,"4":73,"5":67,"6":87,"7":121,"8":228,"9":71,"10":2,"11":35,"12":199,"13":98,"14":67,"15":85,"16":111,"17":226,"18":205,"19":45,"20":194,"21":82,"22":168,"23":250,"24":49,"25":209,"26":234,"27":35,"28":252,"29":125,"30":80,"31":19},"media_session_id":"084f8785151f3411ca8b0352c82c3fc1","audio_codec":"opus"}
[VOICE (436813926735413248:0)]: [WS] >> {"op":3,"d":51150039542}
[VOICE (436813926735413248:0)]: [WS] << {"op":6,"d":51150039542}
Starting
[VOICE (436813926735413248:0)]: [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":4}}

And my former error was that I used member.voiceChannel while it actually is member.voice.channel

Closing as it is a stale issue, reopen or check open issues if this is still an issue.

Still same problem here. Anyone still here?

same problem here

same

??

Em Seg, 20 de jul de 2020 11:11, clickinggames notifications@github.com
escreveu:

same

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/discordjs/discord.js/issues/2978#issuecomment-661064346,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/APO5Y2CHGARGBBNO6NSTQ4DR4RGCDANCNFSM4GHT4NXQ
.

Was this page helpful?
0 / 5 - 0 ratings