djs_rest/endpoints/audit_log.rs
1//! The [audit log endpoint](https://docs.discord.com/developers/resources/audit-log): the
2//! record of administrative actions in a guild.
3
4use djs_model::{audit_log::AuditLog, id::GuildId, rest::GetGuildAuditLog};
5
6use crate::client::boxed;
7use crate::{Error, Request, Rest, Route};
8
9impl Rest {
10 /// [Get Guild Audit Log](https://docs.discord.com/developers/resources/audit-log#get-guild-audit-log):
11 /// returns a page of a guild's audit log entries (50 by default) with the users,
12 /// webhooks, threads and other objects they refer to. Needs `VIEW_AUDIT_LOG`.
13 ///
14 /// The reasons that methods taking a `reason` send (D-086) appear here.
15 ///
16 /// discord.js counterpart: `Guild#fetchAuditLogs`.
17 ///
18 /// # Examples
19 ///
20 /// ```no_run
21 /// # async fn example(rest: djs_rest::Rest, guild_id: djs_model::id::GuildId) -> Result<(), djs_rest::Error> {
22 /// use djs_model::{audit_log::AuditLogEvent, rest::GetGuildAuditLog};
23 ///
24 /// let mut query = GetGuildAuditLog::default();
25 /// query.action_type = Some(AuditLogEvent::MemberBanAdd);
26 /// query.limit = Some(10);
27 /// let log = rest.get_guild_audit_log(guild_id, &query).await?;
28 /// for entry in &log.audit_log_entries {
29 /// println!("{:?} banned {:?}: {:?}", entry.user_id, entry.target_id, entry.reason);
30 /// }
31 /// # Ok(())
32 /// # }
33 /// ```
34 ///
35 /// # Errors
36 ///
37 /// See [`Rest::request`]; `50013` Missing Permissions without `VIEW_AUDIT_LOG`.
38 pub fn get_guild_audit_log<'a>(
39 &'a self,
40 guild_id: GuildId,
41 query: &'a GetGuildAuditLog,
42 ) -> impl Future<Output = Result<AuditLog, Error>> + Send + 'a {
43 boxed(async move {
44 self.call(Request::new(Route::GetGuildAuditLog { guild_id }).query(query))
45 .await
46 })
47 }
48}