diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index a1844af3db4..4224842575b 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -209,6 +209,31 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> { &*guild.member(ctx, msg.author.id).await?, ); channel_id.say(ctx, format!("{:?}", perms)).await?; + } else if let Some(forum_channel_id) = msg.content.strip_prefix("createforumpostin ") { + forum_channel_id + .parse::() + .unwrap() + .create_forum_post( + ctx, + CreateForumPost::new( + "a", + CreateMessage::new() + .add_file(CreateAttachment::bytes(b"Hallo welt!", "lul.txt")), + ), + // CreateForumPost::new( + // "a", + // CreateMessage::new() + // .content("test, i hope that forum posts without attachments still + // work?") .embed(CreateEmbed::new().title("hmmm"). + // description("do they?")), ), + ) + .await?; + } else if let Some(forum_post_url) = msg.content.strip_prefix("deleteforumpost ") { + let (_guild_id, channel_id, _message_id) = + serenity::utils::parse_message_url(forum_post_url).unwrap(); + msg.channel_id.say(ctx, format!("Deleting <#{}> in 10 seconds...", channel_id)).await?; + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + channel_id.delete(ctx).await?; } else { return Ok(()); } diff --git a/src/builder/create_forum_post.rs b/src/builder/create_forum_post.rs index 06652760208..8a0f6872593 100644 --- a/src/builder/create_forum_post.rs +++ b/src/builder/create_forum_post.rs @@ -106,10 +106,14 @@ impl<'a> Builder for CreateForumPost<'a> { /// /// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given. async fn execute( - self, + mut self, cache_http: impl CacheHttp, ctx: Self::Context<'_>, ) -> Result { - cache_http.http().create_forum_post(ctx, &self, self.audit_log_reason).await + let files = self.message.attachments.take_files(); + cache_http + .http() + .create_forum_post_with_attachments(ctx, &self, files, self.audit_log_reason) + .await } } diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs index 85dc539bd02..ffaa7d1b7e3 100644 --- a/src/builder/create_message.rs +++ b/src/builder/create_message.rs @@ -67,7 +67,7 @@ pub struct CreateMessage { sticker_ids: Vec, #[serde(skip_serializing_if = "Option::is_none")] flags: Option, - attachments: EditAttachments, + pub(crate) attachments: EditAttachments, // The following fields are handled separately. #[serde(skip)] diff --git a/src/http/client.rs b/src/http/client.rs index a9007a790fb..1383f19aee8 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -416,18 +416,31 @@ impl Http { .await } - /// Creates a forum post channel in the [`GuildChannel`] given its Id. + /// Shortcut for [`Self::create_forum_post_with_attachments`] pub async fn create_forum_post( &self, channel_id: ChannelId, map: &impl serde::Serialize, audit_log_reason: Option<&str>, ) -> Result { - let body = to_vec(map)?; + self.create_forum_post_with_attachments(channel_id, map, vec![], audit_log_reason).await + } + /// Creates a forum post channel in the [`GuildChannel`] given its Id. + pub async fn create_forum_post_with_attachments( + &self, + channel_id: ChannelId, + map: &impl serde::Serialize, + files: Vec, + audit_log_reason: Option<&str>, + ) -> Result { self.fire(Request { - body: Some(body), - multipart: None, + body: None, + multipart: Some(Multipart { + upload: MultipartUpload::Attachments(files.into_iter().collect()), + payload_json: Some(to_string(map)?), + fields: vec![], + }), headers: audit_log_reason.map(reason_into_header), method: LightMethod::Post, route: Route::ChannelForumPosts {