Skip to content

Commit a1255e8

Browse files
authored
Add method for obtaining the guild id of a Channel (#3390)
Since `Channel` is non-exhaustive, then it's not easily possible for users to match against both the `Guild` and `GuildThread` variants to extract the id of the guild which contains said channel. This helper method allows this use-case.
1 parent e6b1758 commit a1255e8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/model/channel/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ impl Channel {
189189
Self::Private(ch) => ch.id.widen(),
190190
}
191191
}
192+
193+
/// If this is a guild channel or guild thread, returns the corresponding guild's Id.
194+
pub fn guild_id(&self) -> Option<GuildId> {
195+
match self {
196+
Channel::GuildThread(thread) => Some(thread.base.guild_id),
197+
Channel::Guild(channel) => Some(channel.base.guild_id),
198+
Channel::Private(_) => None,
199+
}
200+
}
192201
}
193202

194203
fn extract_type<'de, D>(deserializer: D) -> StdResult<(u64, &'de RawValue), D::Error>

0 commit comments

Comments
 (0)