TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buff

const con = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
})

const player = createAudioPlayer()
console.log(`made player`)
console.log(`buffer`, buffer)
const resource = createAudioResource(buffer)
console.log(`made resource`)

player.play(resource)
console.log(`played resource`)

con.subscribe(player)
console.log(`connection subscribed to player`)

con.on(`error`, (error) => {
console.log(error)
con.destroy()
})
const con = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
})

const player = createAudioPlayer()
console.log(`made player`)
console.log(`buffer`, buffer)
const resource = createAudioResource(buffer)
console.log(`made resource`)

player.play(resource)
console.log(`played resource`)

con.subscribe(player)
console.log(`connection subscribed to player`)

con.on(`error`, (error) => {
console.log(error)
con.destroy()
})
I am currently using this to join a voice channel and play back audio, but I am getting the error "TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received type number (73)" As a sanity check I logged my buffer which of course was indeed a buffer, what am I doing wrong? Output:
made player
buffer <Buffer 49 44 33 04 00 00 00 00 00 22 54 53 53 45 00 00 00 0e 00 00 03 4c 61 76 66 36 30 2e 33 2e 31 30 30 00 00 00 00 00 00 00 00 00 00 00 ff fb 94 64 00 0e ... 3536250 more bytes>
made resource
played resource
connection subscribed to player
Uncaught Exception Stack:
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received type number (73)
at new NodeError (node:internal/errors:405:5)
at _write (node:internal/streams/writable:322:13)
at Writable.write (node:internal/streams/writable:344:10)
at pumpToNode (node:internal/streams/pipeline:136:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
made player
buffer <Buffer 49 44 33 04 00 00 00 00 00 22 54 53 53 45 00 00 00 0e 00 00 03 4c 61 76 66 36 30 2e 33 2e 31 30 30 00 00 00 00 00 00 00 00 00 00 00 ff fb 94 64 00 0e ... 3536250 more bytes>
made resource
played resource
connection subscribed to player
Uncaught Exception Stack:
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received type number (73)
at new NodeError (node:internal/errors:405:5)
at _write (node:internal/streams/writable:322:13)
at Writable.write (node:internal/streams/writable:344:10)
at pumpToNode (node:internal/streams/pipeline:136:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
5 Replies
d.js toolkit
d.js toolkit13mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Paige
PaigeOP13mo ago
node: v20.6.1 djs: @14.13.0 @djs/voice: @0.16.0 (I tried replacing the buffer for a file path, which no longer gave an error but also didn't play anything back) (It ended up working with file path, it was simply unclear that I was missing an intent there.. however the buffer method still isn't working, and throws the same error, I also did try making the buffer into a UInt8Array)
ThePedroo
ThePedroo13mo ago
@Paige createAudioResource doesn't support buffers as input so it's reasonable that it's throwing an error. Maybe you should convert it to a Readable/Passthrough, which would be something like:
const stream = PassThrough()

stream.write(buffer)

...
const stream = PassThrough()

stream.write(buffer)

...
I'm unsure if that would work, but it's a good try
Paige
PaigeOP13mo ago
Yeah I figured that out after reading the source code haha
ThePedroo
ThePedroo13mo ago
🤣 Awesome to know you solved it :)
Want results from more Discord servers?
Add your server