From 15c024e40d1aa35b8636d7075c312ed9a99411eb Mon Sep 17 00:00:00 2001 From: AmokDev Date: Fri, 6 Jun 2025 16:00:24 +0300 Subject: [PATCH] auto-thread in blog channel impl --- .env.example | 1 + src/config.rs | 1 + src/main.rs | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 6c5c807..df14484 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ BOT_TOKEN=YOUR-BOT-TOKEN MEMBER_ROLE_ID=123 WELCOME_CHANNEL_ID=321 +BLOG_CHANNEL_ID=987 ADMIN_ID=1 \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 723ee63..b2f8aa0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,5 +5,6 @@ pub struct Config { pub bot_token: String, pub member_role_id: u64, pub welcome_channel_id: u64, + pub blog_channel_id: u64, pub admin_id: u64, } diff --git a/src/main.rs b/src/main.rs index 59c6a31..a11bba1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,11 @@ use serenity::builder::{CreateInteractionResponse, CreateInteractionResponseMess use serenity::model::application::Interaction; use serenity::model::gateway::Ready; use serenity::model::guild::Member; +use serenity::builder::{CreateThread, CreateMessage}; use serenity::model::id::ChannelId; use serenity::model::channel::Message; use serenity::model::user::OnlineStatus; +use serenity::all::ChannelType; use serenity::gateway::ActivityData; use serenity::prelude::*; use tracing::{warn, error, info}; @@ -28,6 +30,22 @@ impl EventHandler for Handler { return; } + if msg.channel_id == self.config.blog_channel_id { + let therad_builder = CreateThread::new("Обсуждение") + .kind(ChannelType::PublicThread); + let new_thread = msg.channel_id.create_thread_from_message(&ctx.http, msg.id, therad_builder).await; + match new_thread { + Ok(guild_channel) => { + let message_builder = CreateMessage::new() + .content("ого"); + guild_channel.send_message(&ctx.http, message_builder) + .await + .unwrap(); + }, + Err(e) => error!("{}", e) + } + } + if msg.content.contains(":3") { if let Err(why) = msg.channel_id.say(&ctx.http, ":3").await { error!("Error sending message: {why:?}"); @@ -79,7 +97,7 @@ impl EventHandler for Handler { } ctx.set_presence( - Some(ActivityData::playing("/help")), + Some(ActivityData::playing("Rust 🦀")), OnlineStatus::DoNotDisturb, );