lavacord / Lavacord

A easy to use Lavalink client that can be used with any discord api wrapper
Apache License 2.0
78 stars 21 forks source link

TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of ReadableStream. #137

Open TEGRAXD opened 1 week ago

TEGRAXD commented 1 week ago

This error occured when I try to manager.connect()

So for context, i just trying to learn how to use Lavalink through Lavacord. This is just simplified code that reproduce the error.

const { Client, GatewayIntentBits } = require("discord.js");
const { Manager } = require("lavacord");

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });

client.once("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);

  const manager = new Manager([{ id: "default", host: "localhost", port: 2333, password: "yourpassword" }], { user: client.user.id });

  manager.on("ready", (node) => {
    console.log(`Lavalink node "${node.id}" ready!`);
  });

  manager.connect();

  client.on("messageCreate", async (message) => {
    if (message.author.bot) return;
    if (!message.content.startsWith("!play")) return;

    console.log("Received play command!");

    const voiceChannel = message.member.voice.channel;
    if (!voiceChannel) return message.reply("You need to be in a voice channel!");

    const player = manager.create({
      guild: message.guild.id,
      voiceChannel: voiceChannel.id,
      textChannel: message.channel.id,
    });

    try {
      await player.connect();
      await player.search(message.content.slice(6));
      await player.play();
    } catch (error) {
      console.error(error);
      message.reply("Error playing track!");
    }
  });
});

client.login("YOUR_TOKEN");

Error Stack Trace

TypeError: terminated
    at Fetch.onAborted (.\node_modules\undici\lib\web\fetch\index.js:2034:49)
    at Fetch.emit (node:events:513:28)
    at Fetch.terminate (.\node_modules\undici\lib\web\fetch\index.js:93:10)
    at .\node_modules\undici\lib\web\fetch\index.js:506:30   
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  [cause]: TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of ReadableStream
      at new NodeError (node:internal/errors:393:5)
      at eos (node:internal/streams/end-of-stream:65:11)
      at fetchFinale (.\node_modules\undici\lib\web\fetch\index.js:1093:5)
      at mainFetch (.\node_modules\undici\lib\web\fetch\index.js:760:5)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    code: 'ERR_INVALID_ARG_TYPE'
  }
}

Lavacord Version

^2.1.4-v4

Lavalink Version

4.0.6 (latest)

Discord.js Version

^14.15.3

Node Version

v18.10.0
Exodo0 commented 2 days ago

Some time ago, the same thing happened to me and I added this to my intents

GatewayIntentBits.GuildVoiceStates

PapiOphidian commented 2 days ago

For your specific code, I'd also recommend using "lavacord/dist/discord.js" instead of just lavacord. How it's used is a little different, but if you're using an editor with intellisense like VSCode then it shouldn't be too hard. Currently, all that I can spot that's wrong is the fact that you don't have the guild voice states intent like @Exodo0 mentioned, you don't have a send function for forwarding gateway packets from lavacord to your Discord library, you don't forward VOICE_STATE_UPDATE or VOICE_SERVER_UPDATE packets to Lavacord, manager.create should be manager.join and you need to await it for the Player.

Most of these issues can be remedied by switching to the discord.js bindings for lavacord which is the require("lavacord/dist/discord.js")