TypeError: Cannot read properties of undefined (reading 'videoOwnerRenderer')
at Function.Util.getVideo (PROJECT_LOCATION\node_modules\youtube-sr\build\Util.js:1:13984)
at Function.<anonymous> (PROJECT_LOCATION\node_modules\youtube-sr\build\main.js:1:5363)
at step (PROJECT_LOCATION\node_modules\youtube-sr\build\main.js:1:1854)
at Object.next (PROJECT_LOCATION\node_modules\youtube-sr\build\main.js:1:1127)
at fulfilled (PROJECT_LOCATION\node_modules\youtube-sr\build\main.js:1:528)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
The error that I am getting is very similar to the current open issue 26
I believe this can be easily reproducible with this specific video
YouTube.getVideo("https://www.youtube.com/watch?v=kTJczUoc26U")
it simply drops the type error without doing anything with what it returns.
I noticed that the subscribers are null where the subscriber on the actual video is not, and it is this line of code that seems to break the program, but I'm not too sure why it breaks the code, perhaps a ? missing on videoOwnerRenderer as @Ayeven suggested:
(Possible fix : subscribers: info.owner.videoOwnerRenderer.subscriberCountText.simpleText?.replace(" subscribers", "") change to subscribers: info.owner.videoOwnerRenderer?.subscriberCountText?.simpleText ?? " ",)
One more thing, I think the error will pop up for all url, icon and subscriber, because perhaps info.owner is undefined (?), I'm not quite sure
Full code below (typescript)
async function getVideo(messageContent: string, message: Message, serverQueue: ServerQueue, overallQueue: Map<string, ServerQueue>) {
await YouTube.getVideo(messageContent)
.then(async video => {
serverQueue.songs.push({
title: video.title,
url: `https://www.youtube.com/watch?v=${video.id}`,
thumbnail: video.thumbnail.url
});
if (serverQueue.connection)
message.channel.send(`${video.title} has been added to the queue!`, { files: [video.thumbnail.url] });
if (!serverQueue.connection) {
try {
const connection = await message.member.voice.channel.join();
serverQueue.connection = connection;
playSong(message, serverQueue.songs[0], serverQueue, overallQueue);
} catch (err) {
console.log(err);
overallQueue.delete(message.guild.id);
return message.channel.send(err);
}
}
})
.catch(err => console.error(err));
}
Can be reduced to this, while error is still persistantly showing
async function getVideo() {
await YouTube.getVideo("https://www.youtube.com/watch?v=kTJczUoc26U")
.catch(console.error);
}
The error that I am getting is very similar to the current open issue 26
I believe this can be easily reproducible with this specific video
YouTube.getVideo("https://www.youtube.com/watch?v=kTJczUoc26U")
it simply drops the type error without doing anything with what it returns.I noticed that the subscribers are null where the subscriber on the actual video is not, and it is this line of code that seems to break the program, but I'm not too sure why it breaks the code, perhaps a ? missing on videoOwnerRenderer as @Ayeven suggested: (Possible fix :
subscribers: info.owner.videoOwnerRenderer.subscriberCountText.simpleText?.replace(" subscribers", "")
change tosubscribers: info.owner.videoOwnerRenderer?.subscriberCountText?.simpleText ?? " ",
)One more thing, I think the error will pop up for all url, icon and subscriber, because perhaps
info.owner
is undefined (?), I'm not quite sureFull code below (typescript)
Can be reduced to this, while error is still persistantly showing
The object which was returned
Lastly, this is my first time ever posting an Issue on Github, please tell me if I have done anything wrong or I missed anything in the issue, thanks!