-
Notifications
You must be signed in to change notification settings - Fork 859
Description
I'm getting the "Cannot play a resource that has already ended." when I try playing music with this current code:
`const { createAudioPlayer, NoSubscriberBehavior, joinVoiceChannel, createAudioResource } = require('@discordjs/voice');
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
const ytdl = require('ytdl-core');
const stream = ytdl('https://www.youtube.com/watch?v=RgKAFK5djSk', { filter : 'audioonly' });
console.log(stream)
const resource = createAudioResource(stream, {
inlineVolume: true
})
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!')) {
const args = message.content.replace('!', '').split(/ +/);
if (args[0] === 'play') {
try {
const state = resource.audioPlayer.checkPlayable()
if (state == true) return message.reply('A music is already playing.')
} catch (error) { };
const connection = joinVoiceChannel({
channelId: message.channel.id,
guildId: message.channel.guild.id,
adapterCreator: message.channel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
});
console.log(`\n\n\n${resource}`)
player.play(resource)
connection.subscribe(player)
message.reply('Started playing music!')
}`
It makes the bot crashes with that error message (Cannot play a resource that has already ended.).
While I was trying to get the error message again to open an issue, it crashed with this long message (probably the "console.log(resource)").
Not sure how I got it tho.
The error:
node:events:497
throw er; // Unhandled 'error' event
^
AudioPlayerError: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on AudioPlayer instance at:
at Encoder.onStreamError (C:\Users\TufKourio\Desktop\music bot\node_modules@discordjs\voice\dist\index.js:1138:14)
at Object.onceWrapper (node:events:634:26)
at Encoder.emit (node:events:531:35)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
resource: <ref *4> AudioResource {
playStream: Encoder {
_events: {
close: [
[Function (anonymous)],
[Function: onclose],
[Function (anonymous)],
[Function: onclose],
[Function: bound onceWrapper] {
listener: [Function: onFailureCallback]
}
],
error: [
[Function: onerror],
[Function: onError],
[Function: onerror]
],
prefinish: [Function: prefinish],
finish: [
[Function: onfinish],
[Function: onfinish],
[Function: bound onceWrapper] {
listener: [Function: onFailureCallback]
}
],
drain: undefined,
data: undefined,
end: [
[Function: onend],
[Function: onend],
[Function: bound onceWrapper] {
listener: [Function: onFailureCallback]
}
],
readable: [
[Function: bound onceWrapper] {
listener: [Function (anonymous)]
},
[Function: bound onceWrapper] {
listener: [Function: onReadableCallback]
}
],
unpipe: undefined
},
_readableState: ReadableState {
highWaterMark: 16,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 9480639,
[Symbol(kErroredValue)]: Error: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 17580990,
[Symbol(kBufferedValue)]: null,
[Symbol(kErroredValue)]: Error: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
},
allowHalfOpen: true,
_maxListeners: undefined,
_eventsCount: 6,
encoder: null,
_options: {
rate: 48000,
channels: 2,
frameSize: 960,
application: undefined
},
_required: 3840,
_buffer: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
edges: [
<ref *1> {
type: 'ffmpeg pcm',
to: Node { edges: [ [Object], [Object] ], type: 'raw' },
cost: 2,
transformer: [Function: transformer],
from: Node { edges: [ [Circular *1], [Object] ], type: 'arbitrary' }
},
<ref *2> {
type: 'volume transformer',
to: Node { edges: [ [Object], [Circular *2] ], type: 'raw' },
cost: 0.5,
transformer: [Function: transformer],
from: Node { edges: [ [Object], [Circular *2] ], type: 'raw' }
},
<ref *3> {
type: 'opus encoder',
to: Node { edges: [ [Object] ], type: 'opus' },
cost: 1.5,
transformer: [Function: transformer],
from: Node { edges: [ [Circular *3], [Object] ], type: 'raw' }
}
],
metadata: null,
volume: VolumeTransformer {
_events: {
close: [
[Function (anonymous)],
[Function: onclose],
[Function (anonymous)],
[Function: onclose],
[Function: onclose]
],
error: [
[Function: onerror],
[Function: onError],
[Function: onerror],
[Function: onerror]
],
prefinish: [Function: prefinish],
finish: [
[Function: onfinish],
[Function: onfinish],
[Function: onfinish]
],
drain: undefined,
data: undefined,
end: [
[Function: onend],
[Function: onend],
[Function: bound onceWrapper] { listener: [Function: endFn] },
[Function: onend]
],
readable: undefined,
unpipe: undefined
},
_readableState: ReadableState {
highWaterMark: 16384,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 110111230,
[Symbol(kErroredValue)]: Error: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 17581054,
[Symbol(kBufferedValue)]: null,
[Symbol(kErroredValue)]: Error: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
},
allowHalfOpen: true,
_maxListeners: undefined,
_eventsCount: 5,
_readInt: [Function (anonymous)],
_writeInt: [Function (anonymous)],
_bits: 16,
_bytes: 2,
_extremum: 32768,
volume: 1,
_chunk: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
encoder: Encoder {
_events: {
close: [
[Function (anonymous)],
[Function: onclose],
[Function (anonymous)],
[Function: onclose],
[Function: bound onceWrapper] {
listener: [Function: onFailureCallback]
}
],
error: [
[Function: onerror],
[Function: onError],
[Function: onerror]
],
prefinish: [Function: prefinish],
finish: [
[Function: onfinish],
[Function: onfinish],
[Function: bound onceWrapper] {
listener: [Function: onFailureCallback]
}
],
drain: undefined,
data: undefined,
end: [
[Function: onend],
[Function: onend],
[Function: bound onceWrapper] {
listener: [Function: onFailureCallback]
}
],
readable: [
[Function: bound onceWrapper] {
listener: [Function (anonymous)]
},
[Function: bound onceWrapper] {
listener: [Function: onReadableCallback]
}
],
unpipe: undefined
},
_readableState: ReadableState {
highWaterMark: 16,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 9480639,
[Symbol(kErroredValue)]: Error: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 17580990,
[Symbol(kBufferedValue)]: null,
[Symbol(kErroredValue)]: Error: Could not extract functions
at C:\Users\TufKourio\Desktop\music bot\node_modules\ytdl-core\lib\sig.js:20:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
},
allowHalfOpen: true,
_maxListeners: undefined,
_eventsCount: 6,
encoder: null,
_options: {
rate: 48000,
channels: 2,
frameSize: 960,
application: undefined
},
_required: 3840,
_buffer: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
audioPlayer: <ref *5> AudioPlayer {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_state: {
status: 'buffering',
resource: [Circular *4],
onReadableCallback: [Function: onReadableCallback],
onFailureCallback: [Function: onFailureCallback],
onStreamError: [Function: onStreamError]
},
subscribers: [
PlayerSubscription {
connection: VoiceConnection {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
rejoinAttempts: 0,
_state: [Object],
joinConfig: [Object],
packets: [Object],
receiver: [VoiceReceiver],
debug: null,
onNetworkingClose: [Function: bound onNetworkingClose],
onNetworkingStateChange: [Function: bound onNetworkingStateChange],
onNetworkingError: [Function: bound onNetworkingError],
onNetworkingDebug: [Function: bound onNetworkingDebug],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
player: [Circular *5]
}
],
behaviors: { noSubscriber: 'pause', maxMissedFrames: 5 },
debug: [Function (anonymous)],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
playbackDuration: 0,
started: false,
silencePaddingFrames: 5,
silenceRemaining: -1
}
}
Node.js v20.18.0