Skip to content

Commit

Permalink
Fix broken GuildChannel collector functionality (#1446)
Browse files Browse the repository at this point in the history
Currently, `GuildChannel::await_reply` and other collector methods try to await from a "guild" that matches the `GuildChannel`'s ID. This would have functioned normally had default channels not been discontinued (which shared the same ID as the guild), but since they were, the behaviour only works in very old guilds. Furthermore, logic dictates that, since the collector methods are on a `GuildChannel`, they should work by awaiting on the specific channel, but they do not. As such, the collectors are broken. This commit fixes them to work based on the guild channel they're called on instead. 

This commit also fixes an example for `Channel::guild()` where `GuildChannel::name` should be the `GuildChannel` name, not the guild name as the example suggests.
  • Loading branch information
Kot committed Jul 26, 2021
1 parent 3117f1d commit 413e3ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/model/channel/guild_channel.rs
Expand Up @@ -1100,44 +1100,44 @@ impl GuildChannel {
}
}

/// Returns a future that will await one message by this guild.
/// Returns a future that will await one message by this guild channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reply<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
) -> CollectReply<'a> {
CollectReply::new(shard_messenger).guild_id(self.id.0)
CollectReply::new(shard_messenger).channel_id(self.id.0)
}

/// Returns a stream builder which can be awaited to obtain a stream of messages sent by this guild.
/// Returns a stream builder which can be awaited to obtain a stream of messages sent by this guild channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_replies<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
) -> MessageCollectorBuilder<'a> {
MessageCollectorBuilder::new(shard_messenger).guild_id(self.id.0)
MessageCollectorBuilder::new(shard_messenger).channel_id(self.id.0)
}

/// Await a single reaction by this guild.
/// Await a single reaction by this guild channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reaction<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
) -> CollectReaction<'a> {
CollectReaction::new(shard_messenger).guild_id(self.id.0)
CollectReaction::new(shard_messenger).channel_id(self.id.0)
}

/// Returns a stream builder which can be awaited to obtain a stream of reactions sent by this guild.
/// Returns a stream builder which can be awaited to obtain a stream of reactions sent by this guild channel.
#[cfg(feature = "collector")]
#[cfg_attr(docsrs, doc(cfg(feature = "collector")))]
pub fn await_reactions<'a>(
&self,
shard_messenger: &'a impl AsRef<ShardMessenger>,
) -> ReactionCollectorBuilder<'a> {
ReactionCollectorBuilder::new(shard_messenger).guild_id(self.id.0)
ReactionCollectorBuilder::new(shard_messenger).channel_id(self.id.0)
}

/// Creates a webhook with only a name.
Expand Down
6 changes: 3 additions & 3 deletions src/model/channel/mod.rs
Expand Up @@ -83,10 +83,10 @@ impl Channel {
/// # let channel = ChannelId(0).to_channel_cached(&cache).await.unwrap();
/// #
/// match channel.guild() {
/// Some(guild) => {
/// println!("It's a guild named {}!", guild.name);
/// Some(guild_channel) => {
/// println!("It's a guild channel named {}!", guild_channel.name);
/// },
/// None => { println!("It's not a guild!"); },
/// None => { println!("It's not in a guild!"); },
/// }
/// # }
/// ```
Expand Down

0 comments on commit 413e3ef

Please sign in to comment.