Cannot read property 'url' of undefined discord.js - url

I don't know what's wrong in my code, this error not appear everytimes, just sometimes and i don't know why i got this error
Here is the part of code where the error is detected :
const song = {
title: songInfo.videoDetails.title,
url: songInfo.videoDetails.video_url,
thumbnail: songInfo.videoDetails.thumbnails[4].url,
author: songInfo.videoDetails.author.name,
viewCount: songInfo.videoDetails.viewCount,
duration: songInfo.videoDetails.lengthSeconds,
agelimited: songInfo.videoDetails.age_restricted
};
With the const song, i cant get information of a Youtube video to send a message on discord like that :
const Embedaddqueue = new Discord.MessageEmbed()
.setColor('#008000')
.setTitle('Music added to the music queue!')
.setDescription(`**${song.title}** by **${song.author}**`)
.setURL(song.url)
.setImage(song.thumbnail)
return message.channel.send(Embedaddqueue);
But with some video, i get this error when i do "!play https://youtube.com/********" or "!play https://youtu.be/****"
TypeError: Cannot read property 'url' of undefined

Related

How do i style a youtube live stream message?

Hi so i am manually inserting in my live stream using a node js googleapis/youtube package. The message shows as a plain text message, what i would like to know is how can i change the design of this text message so that it is more noticeable like maybe highlighting it? I am currently using the following code
const youtubeService = {};
youtubeService.insertMessage = messageText => {
console.log(myliveChatId);
const response = youtube.liveChatMessages.insert(
{
auth: auth,
part: 'snippet',
resource: {
snippet: {
type: 'textMessageEvent',
liveChatId: myliveChatId,
textMessageDetails: {
messageText: 'hello man'
}
}
}
},
(error) => {
console.log(error);
}
);
console.log(response);
};
EDIT:
This is how a chat message usually appears
what i want is something like this
Note: The message that is inserted onto my livestream via the code wont be through my account but rather someone else's.

Problem when displaying errors in friendly way in Zapier

I'm trying to display errors in a friendly way, but I'm always getting the errors stack trace with console logs that I want to get rid of.
The idea is to create a Lead in our platform using any source, for example, Google Sheets.
When an invalid email is provided in the lead and posted to our API, I'm getting the expected message I want to display followed by the stack trace.
My custom error message is
INVALID FORMAT for email. Object didn't pass validation for format email: as1#mail.
But this is what I'm getting:
INVALID FORMAT for email. Object didn't pass validation for format email: as1#mail. What happened: Starting POST request to https://cosmo-charon-production.herokuapp.com/v1/lead/vehicle Received 500 code from https://cosmo-charon-production.herokuapp.com/v1/lead/vehicle?api-key=gIBp04HVdTgsHShJj6bXKwjbcxXTogsh after 62ms Received content "{"code":"SCHEMA_VALIDATION_FAILED","message":"Request validation failed: Parameter (lead) failed sch" INVALID FORMAT for email. Object didn't pass validation for format email: as1#mail. Console logs:
Image showing error displayed in Zapier
I've added a middleware for ErrorHandling into afterResponse, just as one of the examples provided in Zapier docs.
The function analyzeAndParse() receives an error object from the API and returns a string with the error message translated in a friendly way
const checkForErrors = (response, z) => {
// If we get a bad status code, throw an error, using the ErrorTranslator
if (response.status >= 300) {
throw new Error(analyzeAndParse(response.json))
}
// If no errors just return original response
return response
}
This is the code that creates a Lead in our platform, making a request to our API.
function createLead (z, bundle) {
const industry = bundle.inputData.industry
// add product to request based on the inputFields
leadType[industry].addProductFields(bundle.inputData)
const requestOptions = {
url: `${baseUrl}lead/${_.kebabCase(industry)}`,
method: 'POST',
body: JSON.stringify(checkSourceForCreate(bundle.inputData)),
headers: {
'content-type': 'application/json'
}
}
return z.request(requestOptions).then((response) => {
if (response.status >= 300) {
throw new Error(analyzeAndParse(response.content))
}
const content = JSON.parse(response.content)
if (content && content.leads) {
// get only the last lead from the list of leads
content.lead = content.leads[0]
delete content.leads
}
return content
})
}
Any ideas?
Thanks!

Twilio Video - switch media devices option not working

I am using twilio with twilio-video v beta-2 counting on the master branch of this repohttps://github.com/twilio/video-quickstart-js
I got to display the select media and push the devices into it but when I am trying to updateVideoDevice I got an error
updateVideoDevice error TypeError: track must be a LocalAudioTrack, LocalVideoTrack, LocalDataTrack, or MediaStreamTrack
at Object.INVALID_TYPE (index.js:30952)
at Object.validateLocalTrack (index.js:31469)
at LocalParticipant.unpublishTrack (index.js:17047)
at index.js:17096
at Array.reduce (<anonymous>)
at LocalParticipant.unpublishTracks (index.js:17095)
at index.js:36056
my updateVideoDevice function is as the following
function updateVideoDevice(event) {
const select = event.target;
const localParticipant = room.localParticipant;
if (select.value !== '') {
Video.createLocalVideoTrack({
deviceId: { exact: select.value }
}).then(function(localVideoTrack) {
const tracks = Array.from(localParticipant.videoTracks.values());
localParticipant.unpublishTracks(tracks);
log(localParticipant.identity + " removed track: " + tracks[0].kind);
detachTracks(tracks);
localParticipant.publishTrack(localVideoTrack);
log(localParticipant.identity + " added track: " + localVideoTrack.kind);
const previewContainer = document.getElementById('local-media');
attachTracks([localVideoTrack], previewContainer);
})
.catch(error => {
console.error('updateVideoDevice error' ,error);
});
}
}
can any one explain what I am doing wrong?
Twilio developer evangelist here.
This looks to be a breaking change between Twilio Video JS v1 and v2. In the v2 documentation, calling localParticipant.videoTracks returns a Map of <Track.SID, LocalVideoTrackPublication>. Calling .values() on that map returns an iterator of LocalVideoTrackPublications which is then turned to an array using Array.from.
The issue is that you then pass that array of LocalVideoTrackPublications to localParticipant.unpublishTracks(tracks); which causes the error because unpublishTracks expects an array of LocalTracks not LocalVideoTrackPublications.
You could fix this by mapping over the publications and returning the track property:
const tracks = Array.from(localParticipant.videoTracks.values())
.map(publication => publication.track);
Let me know if that helps.

Skillbar not loading Error message: Cannot read property 'top' of undefined

I am trying to animate a 'Skillbar' using HTML, CSS, JS, and animate.css. I am getting the error:
Error feedback: Uncaught TypeError: Cannot read property 'top' of undefined.
I am using a grid system rather than bootstrap
var skillBarTopPos = jQuery('.skillbar').position().top;
jQuery(document).scroll(function(){
var scrolled_val = $(document).scrollTop().valueOf();
if(scrolled_val>skillBarTopPos-250)
startAnimation();
});
function startAnimation(){
jQuery('.skillbar').each(function(){
jQuery(this).find('.skillbar-bar').animate({
width:jQuery(this).attr('data-percent')
},6000);
});
};

SourceUnavailableError when requesting getUserMedia for video from about: page

Requesting mic with audio:true works perfectly fine, however requesting webcam video, or screen video is failing with SourceUnavailbleError. I have added the string of browser to the preference media.getusermedia.screensharing.allowed_domains
Code for requesting webcam video:
var param = {
// audio: true, // if just this it works fine
video: true // {mediaSource: 'screen'} does not work either
};
navigator.mediaDevices.getUserMedia(param).then(function(stream) {
console.log('success');
})
.catch(function(err) {
console.error('err:', err)
});
To reproduce this error, open up browser console, and paste the code above like this:
Error given is:
err: MediaStreamError { name: "SourceUnavailableError", message: "Failed to allocate videosource", constraint: "", stack: "" }
Do you know how I can get around this SourceUnvailableError?
I did a lot of digging here - https://dxr.mozilla.org/mozilla-central/source/browser/modules/webrtcUI.jsm#201 - but no success yet.
Thanks

Resources