maxcutlyp / YoutubeBot

A self-hosted Discord bot for playing YouTube videos
51 stars 26 forks source link

Bot crashes frequently #7

Closed DubbaThony closed 1 year ago

DubbaThony commented 1 year ago

From my quick testing, bot will crash:

if provided command it fails to understnad:

./youtubebot.py: line 2: import: command not found
Terminated
from: too many arguments
./youtubebot.py: line 4: import: command not found
./youtubebot.py: line 5: import: command not found
./youtubebot.py: line 6: import: command not found
./youtubebot.py: line 7: import: command not found
./youtubebot.py: line 8: import: command not found
./youtubebot.py: line 9: import: command not found
./youtubebot.py: line 10: import: command not found
./youtubebot.py: line 11: import: command not found
from: too many arguments
./youtubebot.py: line 15: syntax error near unexpected token `TOKEN'
./youtubebot.py: line 15: `TOKEN = os.getenv('BOT_TOKEN')'

When video is unavailable:

[youtube] Extracting URL: https://www.youtube.com/watch?v=3LjciZ3Inis
[youtube] 3LjciZ3Inis: Downloading webpage
[youtube] 3LjciZ3Inis: Downloading android player API JSON
ERROR: [youtube] 3LjciZ3Inis: Video unavailable. This video contains content from Believe Music, who has blocked it on copyright grounds
./youtubebot.py: line 2: import: command not found
Terminated
from: too many arguments
./youtubebot.py: line 4: import: command not found
./youtubebot.py: line 5: import: command not found
./youtubebot.py: line 6: import: command not found
./youtubebot.py: line 7: import: command not found
./youtubebot.py: line 8: import: command not found
./youtubebot.py: line 9: import: command not found
./youtubebot.py: line 10: import: command not found
./youtubebot.py: line 11: import: command not found
from: too many arguments
./youtubebot.py: line 15: syntax error near unexpected token `TOKEN'
./youtubebot.py: line 15: `TOKEN = os.getenv('BOT_TOKEN')'

But overall works neat, and I like it that it downloads stuff locally, avoiding some bandwidth waste for my specific use case (often same music playing).

maxcutlyp commented 1 year ago

Hey @DubbaThony,

This looks like the Python script is trying to run with Bash for some reason. Check that the first line of the script is #!/usr/bin/env python3.10 and that running /usr/bin/env python3.10 from the command line drops you into an interactive Python 3.10 shell. If it doesn't, you'll need to install Python 3.10 or, if it's already installed, get its location (which python3.10 or whatever the executable is called) and put that in the shebang (e.g. #!/usr/bin/python3.10, or wherever you found it with which).

DubbaThony commented 1 year ago

Thanks for reply. Yes, indeed I remved the shebang line as I run with python ./script.py. I use asdf to get precisely python the script needs:

root@dubba /opt/discord-music # python --version
Python 3.10.10

I've re-added it (and the shebang is correct for my system) Now bot no longer displays these lines but still crashes and re-starts (which is now improvement) in these conditions

maxcutlyp commented 1 year ago

Yeah, when I wrote this I wasn't really planning on doing much with it, so my error "handling" was pretty primitive - that being, "if any error occurs during a command just restart the entire bot" (see the on_command_error function and the restart script it calls). This was useful when it was in active development because it would ensure that there was always a "clean slate" and that errors didn't propagate, and it meant the bot almost never totally "died".

However, in the situations you've highlighted these errors should probably be handled better. It's probably out of scope of what I have the time to do, but I'm happy to look at a PR to improve error handling.

Btw, if you want to keep the script "shebang-less" you can probably just change the restart script to directly call python, i.e. change the ./youtubebot.py line to python ./youtubebot.py.

DubbaThony commented 1 year ago

That's very fair enough.

While I never touched python I will try to get some free time to figure out how to do it better.

maxcutlyp commented 1 year ago

Sounds good! I'll close this issue now if your original issue is fixed - if/when you want to take a look, just open a PR and I'll be happy to review.

DubbaThony commented 1 year ago

Hi, I opened the PR and it's been stale for over a week. I know GH notifs can be a bear sometimes, so just in case you missed it: PR #8 small bump. @maxcutlyp