No video id found ytdl

639 Views Asked by At

Hello lately ive been developing a music bot on discord and i got it to join and leave perfectly but playing music is just annoying and some reason play and playStream doesnt work. With the bot i would like a person to message the name of a song and it'll get a url out of it but each time is says no video id found here is my code;

client.on("message", (message) => {
  if (message.content.startsWith(">p")){
let string = message.content;
let lastWord = string.slice(2);

    if (lastWord != ">p"){
          const {joinVoiceChannel} = require('@discordjs/voice')
    const voice = require('@discordjs/voice')
  
const connection = joinVoiceChannel({
    channelId: message.member.voice.channel.id,
    guildId: message.member.guild.id,
    adapterCreator: message.member.guild.voiceAdapterCreator
})
const stream = ytdl(lastWord, {filter: 'audioonly', quality: 'highestaudio'})


         stream.pipe(fs.createWriteStream('tmp_buf_audio.mp3')).on('end', () => {

        connection.playStream(fs.createReadStream('tmp_buf_audio.mp3'))
    }
          )};
 
  }
});

here is also the error i get;

/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63
    throw Error(`No video id found: ${str}`);
          ^

Error: No video id found:  
    at Object.exports.getVideoID (/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63:11)
    at Function.exports.<computed> [as getInfo] (/home/runner/Bot-Project/node_modules/ytdl-core/lib/info.js:484:29)
    at ytdl (/home/runner/Bot-Project/node_modules/ytdl-core/lib/index.js:19:8)
    at Client.<anonymous> (/home/runner/Bot-Project/index.js:83:16)
    at Client.emit (node:events:402:35)
    at Client.emit (node:domain:475:12)
Hint: hit control+c anytime to enter REPL.
Project is running!
(node:7809) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
Hint: hit control+c anytime to enter REPL.
Project is running!
(node:7923) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63
    throw Error(`No video id found: ${str}`);
          ^

Error: No video id found:  let it go
    at Object.exports.getVideoID (/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63:11)
    at Function.exports.<computed> [as getInfo] (/home/runner/Bot-Project/node_modules/ytdl-core/lib/info.js:484:29)
    at ytdl (/home/runner/Bot-Project/node_modules/ytdl-core/lib/index.js:19:8)
    at Client.<anonymous> (/home/runner/Bot-Project/index.js:83:16)
    at Client.emit (node:events:402:35)
    at Client.emit (node:domain:475:12)
    at MessageCreateAction.handle (/home/runner/Bot-Project/node_modules/discord.js/src/client/actions/MessageCreate.js:34:18)
    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/Bot-Project/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/runner/Bot-Project/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
Emitted 'error' event on PassThrough instance at:

repl process died unexpectedly: exit status 1
 
1

There are 1 best solutions below

0
On

I see you are using node-ytdl-core.
The usage of ytdl('.....'), is wrong, it should be instead used as following : ytdl(url, [options]).
Go through https://www.npmjs.com/package/ytdl-core