Confused on how Cache & HTTP interact #2365
-
The following code fails with "Guild not found in the cache"... if command == "config" {
if !msg
.member(&ctx.http)
.await?
.permissions(&ctx.cache)?
.manage_guild()
{
msg.reply(
&ctx.http,
"You need the Manage Server permission to run this command!",
)
.await?;
return Ok(());
} How do I do this such that the member is fetched only if they're not cached? Similar to some sort of Discord.js code |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
...that's not your problem, though. Your error originates from |
Beta Was this translation helpful? Give feedback.
Message::member
accepts a parameter that implementsCacheHttp
, or in other words, a type that can provide access to the http client and/or cache. This trait is used wherever a function needs the http client, but may optionally use the cache first if it is given one. Right now, by passing&ctx.http
, you're providingMessage::member
only the http client. You want to pass a reference to theContext
instead:msg.member(ctx)
(assumingctx
is&Context
), as theContext
stores both the http client and cache. This way,Message::member
will try searching the cache for the message author's member data first before attempting a http request....that's not your problem, though. Your error originates f…