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
版权声明:本文标题:telegram bot - Teloxide message handler error: Injectable< , , , > is not implemented - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305315a1932549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论