serenity/builder/
create_sticker.rs1#[cfg(feature = "http")]
2use super::Builder;
3use super::CreateAttachment;
4#[cfg(feature = "http")]
5use crate::http::CacheHttp;
6#[cfg(feature = "http")]
7use crate::internal::prelude::*;
8#[cfg(feature = "http")]
9use crate::model::prelude::*;
10
11#[derive(Clone, Debug)]
15#[must_use]
16pub struct CreateSticker<'a> {
17 name: String,
18 description: String,
19 tags: String,
20 file: CreateAttachment,
21 audit_log_reason: Option<&'a str>,
22}
23
24impl<'a> CreateSticker<'a> {
25 pub fn new(name: impl Into<String>, file: CreateAttachment) -> Self {
27 Self {
28 name: name.into(),
29 tags: String::new(),
30 description: String::new(),
31 file,
32 audit_log_reason: None,
33 }
34 }
35
36 pub fn name(mut self, name: impl Into<String>) -> Self {
40 self.name = name.into();
41 self
42 }
43
44 pub fn description(mut self, description: impl Into<String>) -> Self {
48 self.description = description.into();
49 self
50 }
51
52 pub fn tags(mut self, tags: impl Into<String>) -> Self {
56 self.tags = tags.into();
57 self
58 }
59
60 pub fn file(mut self, file: CreateAttachment) -> Self {
64 self.file = file;
65 self
66 }
67
68 pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
70 self.audit_log_reason = Some(reason);
71 self
72 }
73}
74
75#[cfg(feature = "http")]
76#[async_trait::async_trait]
77impl Builder for CreateSticker<'_> {
78 type Context<'ctx> = GuildId;
79 type Built = Sticker;
80
81 async fn execute(
92 self,
93 cache_http: impl CacheHttp,
94 ctx: Self::Context<'_>,
95 ) -> Result<Self::Built> {
96 #[cfg(feature = "cache")]
97 crate::utils::user_has_guild_perms(
98 &cache_http,
99 ctx,
100 Permissions::CREATE_GUILD_EXPRESSIONS,
101 )?;
102
103 let map = [("name", self.name), ("tags", self.tags), ("description", self.description)];
104 cache_http.http().create_sticker(ctx, map, self.file, self.audit_log_reason).await
105 }
106}