Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TEGRAXD opened this issue Jun 26, 2024 · 2 comments

Comments

@TEGRAXD
Copy link

TEGRAXD commented Jun 26, 2024

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
Copy link

Exodo0 commented Jul 2, 2024

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

GatewayIntentBits.GuildVoiceStates

@PapiOphidian
Copy link
Collaborator

PapiOphidian commented Jul 2, 2024

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants