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

Play function Message Return and Console Log. #22

Closed
KayPls opened this issue Apr 6, 2020 · 2 comments
Closed

Play function Message Return and Console Log. #22

KayPls opened this issue Apr 6, 2020 · 2 comments

Comments

@KayPls
Copy link

KayPls commented Apr 6, 2020

Hello,

Everything works as intended, so thank you for that.

To note: my prefix is ( . )
The .play <YT URL video ID> function works perfectly, but I would like to know how to create a message return when needed:
(1) When .play is entered alone or .play <Song title>, I want to return a message to the user stating to enter a valid YT URL in order for the function to work.
(a) Also but not as important, I would like to get rid of the console errors that stem from not entering .play <YT URL video ID> exactly (unhandlePromiseRejectionWarnings).

Thank you for your time!

@jdinhwork
Copy link

jdinhwork commented Apr 6, 2020

Hi, what you’re looking for is a function to validate whether or not args[1] is a YouTube URL.

Here’s a function that will do so.

function validateYouTubeUrl()
{
var url = $('#youTubeUrl').val();
if (url != undefined || url != '') {
var regExp = /^.(youtu.be/|v/|u/\w/|embed/|watch?v=|&v=|?v=)([^#\&\?]).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
// Do anything for being valid
// if need to change the url to embed url then use below line
$('#ytplayerSide').attr('src', 'https://www.youtube.com/embed/' + match[2] + '?autoplay=0');
}
else {
// Do anything for not being valid
}
}
}

Replace the //Do anything for not being valid with
message.channel.send(“Enter valid Youtube URL”)

And //Do anything for being valid with the function to perform the !play command.

Hopefully that helps! (:

@KayPls
Copy link
Author

KayPls commented Apr 7, 2020

Thank you very much for the quick and helpful response, as well as the detailed tutorial!

@KayPls KayPls closed this as completed Apr 7, 2020
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

2 participants