tgbot-cpp icon indicating copy to clipboard operation
tgbot-cpp copied to clipboard

Please help

Open Sasha32global opened this issue 11 months ago • 1 comments

How can i send messages with timer? When i try this code:

try {
    printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
    TgBot::TgLongPoll longPoll(bot);
    while (true) {
        time_t ttime = time(0);
        tm* local_time = localtime(&ttime);
        if (local_time->tm_hour == 10 && local_time->tm_min == 57) {
            printf("Report send in\n" + local_time->tm_hour + local_time->tm_min);
            bot.getEvents().
            bot.getApi().sendMessage(IdAdmin, u8"Recieved message?");
        }
        longPoll.start();
    }
}
catch (TgBot::TgException& e) {
    printf("error: %s\n", e.what());
}

What i'm doing wrong?

Sasha32global avatar Jan 30 '25 08:01 Sasha32global

The function longPoll.start() blocks for 10 seconds by default. So local_time->tm_hour == 10 && local_time->tm_min == 57 won't execute correctly.

okman334 avatar Aug 31 '25 11:08 okman334