diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 76f8e2e75b6..bed270e2939 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -14,6 +14,9 @@ mod scheduled_event; mod system_channel; mod welcome_screen; +#[cfg(feature = "model")] +use std::borrow::Cow; + use serde::de::Error as DeError; #[cfg(feature = "model")] use tracing::error; @@ -1644,6 +1647,9 @@ impl Guild { /// Gets a user's [`Member`] for the guild by Id. /// + /// If the cache feature is enabled [`Self::members`] will be checked + /// first, if so, a reference to the member will be returned. + /// /// # Errors /// /// Returns an [`Error::Http`] if the user is not in @@ -1653,8 +1659,14 @@ impl Guild { &self, cache_http: impl CacheHttp, user_id: impl Into, - ) -> Result { - self.id.member(cache_http, user_id).await + ) -> Result> { + let user_id = user_id.into(); + + if let Some(member) = self.members.get(&user_id) { + Ok(Cow::Borrowed(member)) + } else { + cache_http.http().get_member(self.id.0, user_id.0).await.map(Cow::Owned) + } } /// Gets a list of the guild's members.