aquelemiguel / parrot

🦜 A hassle-free, highly performant, self-hosted Discord music bot with YouTube and Spotify support. Powered by yt-dlp.
MIT License
136 stars 44 forks source link

Bot cannot play any song #199

Closed rafaeldamasceno closed 2 years ago

rafaeldamasceno commented 2 years ago

📝 Description

When the bot boots and when playing a song, an error occurs which prevents the bot from playing anything.

thread 'tokio-runtime-worker' panicked at 'failed to create command permission: Http(UnsuccessfulRequest(ErrorResponse { status_code: 403, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("discord.com")), port: None, path: "/api/v9/applications/207250767935963137/guilds/134403220385693696/commands/934962491493085264/permissions", query: None, fragment: None }, error: DiscordJsonError { code: 20001, message: "Bots cannot use this endpoint", errors: [] } }))', src/handlers/serenity.rs:107:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/result.rs:1749:5
   3: parrot::handlers::serenity::SerenityHandler::set_commands::{{closure}}
   4: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   5: tokio::runtime::task::core::CoreStage<T>::poll
   6: tokio::runtime::task::harness::poll_future
   7: tokio::runtime::task::harness::Harness<T,S>::poll
   8: std::thread::local::LocalKey<T>::with
   9: tokio::runtime::thread_pool::worker::Context::run_task
  10: tokio::runtime::thread_pool::worker::Context::run
  11: tokio::macros::scoped_tls::ScopedKey<T>::set
  12: tokio::runtime::thread_pool::worker::run
  13: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  14: tokio::runtime::task::harness::Harness<T,S>::poll
  15: tokio::runtime::blocking::pool::Inner::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', src/handlers/serenity.rs:344:53
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
   2: core::panicking::panic
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:48:5
   3: parrot::handlers::serenity::SerenityHandler::run_command::{{closure}}
   4: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   5: tokio::runtime::task::core::CoreStage<T>::poll
   6: tokio::runtime::task::harness::poll_future
   7: tokio::runtime::task::harness::Harness<T,S>::poll
   8: std::thread::local::LocalKey<T>::with
   9: tokio::runtime::thread_pool::worker::Context::run_task
  10: tokio::runtime::thread_pool::worker::Context::run
  11: tokio::macros::scoped_tls::ScopedKey<T>::set
  12: tokio::runtime::thread_pool::worker::run
  13: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  14: tokio::runtime::task::harness::Harness<T,S>::poll
  15: tokio::runtime::blocking::pool::Inner::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

🪜 Reproduction Steps

  1. Run the bot
  2. Use the /play command

ℹ Environment / Computer Info

Key Value
Parrot version v1.4.2
Operating System Ubuntu 20.04.4 LTS focal
Kernel Linux 5.15.0-41-generic x86_64
CPU Intel(R) Celeron(R) N5095 @ 2.00GHz
RAM 16 GB

📸 Screenshots

image

afonsojramos commented 2 years ago

This is most likely due to some change on Discord's side. Songbird had an update recently that might fix this, however, it requires some investigation.

rafaeldamasceno commented 2 years ago

Upon further investigation, I have found out that the bot does not play in servers where it was not able to create a DJ role (which the now deprecated endpoint does not allow).

afonsojramos commented 2 years ago

Right! This was indeed a recent change in how they are handling permissions. Reading from here it seems that the bot token is no longer supported and now a bearer token is needed with the applications.commands.permissions.update scope.

rafaeldamasceno commented 2 years ago

Since Discord introduced a way to manage all of the permissions for registered interactions on a guild, what if I remove the current code for the role creation/permission setting and deal with this issue and #146, which is not necessary anymore?

StaticRocket commented 2 years ago

@afonsojramos @rafaeldamasceno That's what I was talking about in #196

Bearer tokens are not a safe way to do that because they need to come from an account that has permission to add roles in the server, and they have to be renewed constantly. This was a not so subtle push to get bots to stop setting up their own management groups and instead use the manual role+permission per command system they added to the client. I'll freshen up my draft PR for this now that songbird and serenity have the new release I was waiting for.

rafaeldamasceno commented 2 years ago

You're absolutely right, I overlooked that the changes were already causing the bot not to work at the time you reported it. I'll close this issue as a duplicate of #196.