From 988b5cf1712238057379cd8b7cb80f95bab21a14 Mon Sep 17 00:00:00 2001 From: kangalioo Date: Wed, 28 Jul 2021 10:47:30 +0200 Subject: [PATCH 1/2] Make GuildChannel::send_message work in threads When the cache feature is enabled, GuildChannel::send_message invokes utils::user_has_perms which tries to look up the thread in the channels cache, fails and throws a model::Error::ChannelNotFound. send_message lazily propagates any error, so the cache miss brings down the whole send_message invocation. --- src/model/channel/guild_channel.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 3b3f835e6ed..94f199023da 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -957,7 +957,9 @@ impl GuildChannel { if let Some(cache) = cache_http.cache() { let req = Permissions::SEND_MESSAGES; - if !utils::user_has_perms(&cache, self.id, Some(self.guild_id), req).await? { + if utils::user_has_perms(&cache, self.id, Some(self.guild_id), req).await + == Ok(false) + { return Err(Error::Model(ModelError::InvalidPermissions(req))); } } From 977769348ba68eb89becd5a70c307b3b8dc3a1d7 Mon Sep 17 00:00:00 2001 From: kangalioo Date: Wed, 28 Jul 2021 11:08:06 +0200 Subject: [PATCH 2/2] Ehm oops How did I manage to mess a trivial one line change up --- src/model/channel/guild_channel.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 94f199023da..7602074fa28 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -957,8 +957,8 @@ impl GuildChannel { if let Some(cache) = cache_http.cache() { let req = Permissions::SEND_MESSAGES; - if utils::user_has_perms(&cache, self.id, Some(self.guild_id), req).await - == Ok(false) + if let Ok(false) = + utils::user_has_perms(&cache, self.id, Some(self.guild_id), req).await { return Err(Error::Model(ModelError::InvalidPermissions(req))); }