diff --git a/examples/simple_commands_bot/src/main.rs b/examples/simple_commands_bot/src/main.rs index 4940233b..7ba91528 100644 --- a/examples/simple_commands_bot/src/main.rs +++ b/examples/simple_commands_bot/src/main.rs @@ -1,8 +1,9 @@ use teloxide::{prelude::*, utils::command::BotCommand}; -use std::{error::Error, sync::Arc}; +use std::error::Error; +use teloxide::types::Me; -#[derive(BotCommand)] +#[derive(BotCommand, Clone)] #[command(rename = "lowercase", description = "These commands are supported:")] enum Command { #[command(description = "display this text.")] @@ -14,11 +15,11 @@ enum Command { } async fn answer( - bot: Arc>, - message: Arc, - command: Arc, + bot: AutoSend, + message: Message, + command: Command, ) -> Result<(), Box> { - match command.as_ref() { + match command { Command::Help => bot.send_message(message.chat.id, Command::descriptions()).await?, Command::Username(username) => { bot.send_message(message.chat.id, format!("Your username is @{}.", username)).await? @@ -42,6 +43,8 @@ async fn main() { let bot = Bot::from_env().auto_send(); - let bot_name: String = "".into(); // panic!("Your bot's name here"); + let Me { user: bot_user, .. } = bot.get_me().await.unwrap(); + let bot_name = bot_user.username.expect("Bots must have usernames"); + teloxide::commands_repl(bot, bot_name, answer, Command::ty()).await; }