diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 5a3531f6b34..9da47011751 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -141,7 +141,13 @@ impl serenity::Framework for Framework { self.shard_manager = Some(client.shard_manager.clone()); if self.options.initialize_owners { - if let Err(e) = insert_owners_from_http(&client.http, &mut self.options.owners).await { + if let Err(e) = insert_owners_from_http( + &client.http, + &mut self.options.owners, + &self.options.initialized_team_roles, + ) + .await + { tracing::warn!("Failed to insert owners from HTTP: {e}"); } } @@ -239,6 +245,7 @@ fn message_content_intent_sanity_check( pub async fn insert_owners_from_http( http: &serenity::Http, owners: &mut std::collections::HashSet, + initialized_teams: &Option>, ) -> Result<(), serenity::Error> { let application_info = http.get_current_application_info().await?; @@ -253,7 +260,16 @@ pub async fn insert_owners_from_http( continue; } - if let TeamMemberRole::Admin | TeamMemberRole::Developer = member.role { + // Default configuration. + let Some(initialized_teams) = initialized_teams else { + if let TeamMemberRole::Admin | TeamMemberRole::Developer = member.role { + owners.insert(member.user.id); + } + continue; + }; + + // s has specified the teams they want to be considered "Owner". + if initialized_teams.iter().any(|r| *r == member.role) { owners.insert(member.user.id); } } diff --git a/src/structs/framework_options.rs b/src/structs/framework_options.rs index 3ec310e9c3c..1f7403e1c55 100644 --- a/src/structs/framework_options.rs +++ b/src/structs/framework_options.rs @@ -67,6 +67,13 @@ pub struct FrameworkOptions { /// /// True by default. pub initialize_owners: bool, + /// If set and [`Self::initialize_owners`] is `true`, the selected teams will be initialized + /// using the results of [`serenity::Http::get_current_application_info()`]. + /// + /// When set to `None`, only users with the Developer and Admin roles are initialized. + /// + /// None by default. + pub initialized_team_roles: Option>, // #[non_exhaustive] forbids struct update syntax for ?? reason #[doc(hidden)] pub __non_exhaustive: (), @@ -120,6 +127,7 @@ where prefix_options: Default::default(), owners: Default::default(), initialize_owners: true, + initialized_team_roles: None, __non_exhaustive: (), } }