Forums

My Telegram bot isn't working :( Please help

When i run it on my local machine it works perfect. But when im trying to run it here nothing happens. 0 errors just nothing. Its a simple bot to count and sending message in telegram group. You can try it with your own API and group ID on your local PC and here if you want to see. Please help idk what to do. Here is the code

 import logging
import telegram
from telegram.ext import Updater, MessageHandler, Filters
from datetime import datetime, timedelta, time
import pytz
import schedule
import time as mod_time
import random
from telegram import ParseMode


TOKEN = 'your_token'


GROUP_CHAT_ID = -your_chat_id


updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

proxy_total = 0
accounts_total = 0

message_ids_today = []

def reset_totals():

    global proxy_total
    global accounts_total
    proxy_total = 0
    accounts_total = 0

def analyze_message(update, context):
    global has_messages_today

    message = update.message
    if message:
        message_text = message.text


        if update.message.from_user:

            message_ids_today.append(message.message_id)

        proxy_sum = 0
        accounts_sum = 0

        words = message_text.split()
        for i in range(1, len(words)):
            if words[i] in ["Proxy", "Proxies"]:
                try:
                    proxy_sum += int(words[i - 1])
                except ValueError:
                    pass
            elif words[i] in ["accs", "accounts", "account"]:
                try:
                    accounts_sum += int(words[i - 1])
                except ValueError:
                    pass

        global proxy_total
        global accounts_total
        proxy_total += proxy_sum
        accounts_total += accounts_sum


        print(f"Proxy sum: {proxy_total}, Accounts sum: {accounts_total}")

def send_daily_stats():
    global message_ids_today, has_messages_today
    has_messages_today = False  # Добавляем объявление переменной
    # here is moscow time you can set yours
    tz = pytz.timezone('Europe/Moscow')
    now = datetime.now(tz)

    if message_ids_today:
        has_messages_today = True

    # set the time to send msg here
    if now.hour == 1 and now.minute == 35 and has_messages_today:

        today = now - timedelta(days=1)
        message = f"ℹ️ <b>Today stats:</b> ℹ️\n <i><b>➖ Proxies:</b></i> <code>{proxy_total}</code>\n <i><b>➖ Accs:</b></i> <code>{accounts_total}</code>"
        updater.bot.send_message(chat_id=GROUP_CHAT_ID, text=message, parse_mode=ParseMode.HTML)


    message_ids_today.clear()
    has_messages_today = False


message_handler = MessageHandler(Filters.text & ~Filters.command, analyze_message)
dispatcher.add_handler(message_handler)

# time here as well
schedule.every().day.at("01:35").do(send_daily_stats)


updater.start_polling()


while True:
    schedule.run_pending()
    mod_time.sleep(1)

How are you running your script on PythonAnywhere?

How are you running your script on PythonAnywhere?

Bash -> new console -> python *.py I tried to run it from file as well and same issue :( Is there any other options? Tbh i dont think its because of running method but hope im wrong

You could add some logging to see where it fails / hangs (if it really does). Also mind that it would not work in a long run as our consoles are not designed for long running jobs. You should consider using an Always-on task feature instead.