pub struct WebhooksCache(/* private fields */);Expand description
Cache to hold webhooks, keyed by channel IDs for general usage
Implementations§
Source§impl WebhooksCache
impl WebhooksCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new webhook cache
§Invalidation warning
Refer to the docs for WebhooksCache::update to avoid invalidation
Sourcepub async fn get_infallible(
&self,
http: &Client,
channel_id: Id<ChannelMarker>,
name: &str,
) -> Result<Ref<'_, Id<ChannelMarker>, Webhook>, Error>
pub async fn get_infallible( &self, http: &Client, channel_id: Id<ChannelMarker>, name: &str, ) -> Result<Ref<'_, Id<ChannelMarker>, Webhook>, Error>
Convenience function to get from the cache, requesting it from the API if it doesn’t exist, creating it if it’s also not returned
§Required permissions
Make sure the bot has MANAGE_WEBHOOKS permission in the given channel
§Errors
Returns an Error::Http or Error::Deserialize if the webhook
isn’t in the cache
§Panics
If the webhook that was just inserted to the cache somehow doesn’t exist
Sourcepub async fn create(
&self,
create_webhook: CreateWebhook<'_>,
) -> Result<(), Error>
pub async fn create( &self, create_webhook: CreateWebhook<'_>, ) -> Result<(), Error>
Creates the passed webhook and caches it, it takes a CreateWebhook
instead of a Webhook to reduce boilerplate and avoid clones
§Errors
Returns Error::Http or Error::Deserialize
Sourcepub fn get(
&self,
channel_id: Id<ChannelMarker>,
) -> Option<Ref<'_, Id<ChannelMarker>, Webhook>>
pub fn get( &self, channel_id: Id<ChannelMarker>, ) -> Option<Ref<'_, Id<ChannelMarker>, Webhook>>
Returns the webhook for the given channel_id, if it exists
Sourcepub async fn update(
&self,
event: &Event,
http: &Client,
permissions: PermissionsSource<'_>,
) -> Result<(), Error>
pub async fn update( &self, event: &Event, http: &Client, permissions: PermissionsSource<'_>, ) -> Result<(), Error>
Removes the cached webhooks for the given event’s channel or guild
Unless the event is WebhookUpdate, this function isn’t actually
async, http and permissions aren’t used, and it isn’t fallible
http is required because Discord doesn’t send info about updated
webhooks in the event
permissions is required because the bot needs MANAGE_WEBHOOKS
permissions to request webhooks
§Invalidation warning
You should run this on ChannelDelete, GuildDelete and
WebhookUpdate events to make sure deleted webhooks are removed
from the cache, or else executing a cached webhook will return
Unknown Webhook errors
§Errors
Returns Error::Http, Error::Deserialize, or when
[PermissionsSource::Cache] is passed, Error::CachePermissions