admin管理员组

文章数量:1122832

My bot should identify message style, so I have create handler As you can see in my code, I use Arc<RwLock>. But I have met a challenges. Please help me

This is my error when the code that's been running perfectly fine before is now throwing this error:

error[E0277]: the trait bound `fn(teloxide::Bot, teloxide::prelude::Message, Arc<tokio::sync::RwLock<setting_opts::SettingOpts>>) -> impl Future<Output = std::result::Result<(), RequestError>> {answer_replyed_message}: Injectable<_, _, _>` is not satisfied
  --> src/main.rs:81:34
   |
81 |         .branch(dptree::endpoint(answer_replyed_message))
   |                 ---------------- ^^^^^^^^^^^^^^^^^^^^^^ the trait `Injectable<_, _, _>` is not implemented for fn item `fn(Bot, Message, Arc<RwLock<SettingOpts>>) -> impl Future<Output = Result<(), ...>> {answer_replyed_message}`
   |                 |
   |                 required by a bound introduced by this call
   |
   = help: the following other types implement trait `Injectable<Input, Output, FnArgs>`:
             `Asyncify<Func>` implements `Injectable<Input, Output, ()>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B)>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B, C)>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B, C, D)>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B, C, D, E)>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B, C, D, E, F)>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B, C, D, E, F, G)>`
             `Asyncify<Func>` implements `Injectable<Input, Output, (A, B, C, D, E, F, G, H)>`

I have the following code:

use std::{sync::Arc, time, env};
use teloxide::types::{ChatId, InputFile, InlineKeyboardButton, InlineKeyboardMarkup, ReplyMarkup, ForceReply};
use teloxide::{ prelude::*, utils::command::BotCommands };
use tokio::signal;
use tokio::sync::RwLock;
use mysql::*;
use mysql::prelude::*;


pub mod setting_opts;

use setting_opts::*;


// Add this function to establish database connection
fn get_conn_pool() -> Pool {
    let url = "mysql://root:@localhost:3306/gorilla_buy_bot";    
    Pool::new(url).unwrap()
}


#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();
    pretty_env_logger::init();
    log::info!("Starting Gorilla Buy...");

    let bot: Bot = Bot::from_env();

    let bot_commands = Command::bot_commands();
    if bot.set_my_commands(bot_commands).await.is_err() {
        log::warn!("Could not set up the commands.");
    }

    let setting_opts_arc = Arc::new(RwLock::new(SettingOpts::default()));

    // Initialize database connection
    let pool = get_conn_pool();
    
    // Create tables if they don't exist
    init_database(&pool).expect("Failed to initialize database");
    
    let callback_handler = Update::filter_callback_query()
    .endpoint(answer_button);
    
    let message_handler = Update::filter_message()
    .branch(
        dptree::filter(|msg: Message| {
            // Check if this message is a reply to a bot's message with ForceReply
            msg.reply_to_message()
            .and_then(|reply| reply.from())
            .map_or(false, |user| user.is_bot)
        })
        .branch(dptree::endpoint(answer_replyed_message))
    )
    .filter_command::<Command>()
    .endpoint(answer_command);

    let handler = dptree::entry()
        .branch(message_handler)
        .branch(callback_handler);

    Dispatcher::builder(bot, handler)
        .dependencies(dptree::deps![setting_opts_arc.clone()])
        .enable_ctrlc_handler()
        .build()
        .dispatch()
        .await;
    
}


async fn answer_replyed_message(bot: Bot, msg: Message, setting_opts_arc: Arc<RwLock<SettingOpts>>) -> ResponseResult<()> {
 
...

}

I think this is due to dependencies in fn answer_replyed_message.
Please help me

本文标签: telegram botTeloxide message handler error Injectableltgt is not implementedStack Overflow