So this is the code which is bringing up
AttributeError: 'NoneType' object has no attribute 'bot'
from telegram.ext import CallbackContext
from telegram import Bot
import os
# Initialize your bot with the token from environment variable
bot_token = os.getenv('BOT_TOKEN')
if not bot_token:
raise RuntimeError('BOT_TOKEN environment variable is not set.')
bot = Bot(bot_token)
# Messages for notifications
START_WORKDAY_MESSAGE_DRIVERS = "???? Work day: Notification system started! Get ready for a productive day ahead. ????"
END_WORKDAY_MESSAGE_DRIVERS = "???? Job ended for today. Thank you for your hard work! See you tomorrow. ????"
START_WORKDAY_MESSAGE_STUDENTS = "???? Shuttle service is now available! You can start requesting rides. ????"
END_WORKDAY_MESSAGE_STUDENTS = "???? Shuttle service has ended for today. See you again tomorrow! ????"
# Group ID intentionally removed
drivers_group_chat_id = -xxxxxxxxxx
pwd_group_chat_id = -xxxxxxxxxx
async def notify_workday_start_drivers(context: CallbackContext) -> None:
await context.bot.send_message(drivers_group_chat_id, START_WORKDAY_MESSAGE_DRIVERS)
async def notify_workday_end_drivers(context: CallbackContext) -> None:
await context.bot.send_message(drivers_group_chat_id, END_WORKDAY_MESSAGE_DRIVERS)
async def notify_workday_start_students(context: CallbackContext) -> None:
await context.bot.send_message(pwd_group_chat_id, START_WORKDAY_MESSAGE_STUDENTS)
async def notify_workday_end_students(context: CallbackContext) -> None:
await context.bot.send_message(pwd_group_chat_id, END_WORKDAY_MESSAGE_STUDENTS)
I’ve already deployed the bot to heroku and upon running the bot and it get’s to the time to send the message I get the following error in the heroku logs
2024-06-16T23:07:00.043132+00:00 app[web.1]: Traceback (most recent call last):
2024-06-16T23:07:00.043133+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
2024-06-16T23:07:00.043133+00:00 app[web.1]: retval = await job.func(*job.args, **job.kwargs)
2024-06-16T23:07:00.043134+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-16T23:07:00.043134+00:00 app[web.1]: File "/app/notifications.py", line 28, in notify_workday_end_drivers
2024-06-16T23:07:00.043135+00:00 app[web.1]: await context.bot.send_message(drivers_group_chat_id, END_WORKDAY_MESSAGE_DRIVERS)
2024-06-16T23:07:00.043135+00:00 app[web.1]: ^^^^^^^^^^^
2024-06-16T23:07:00.043135+00:00 app[web.1]: AttributeError: 'NoneType' object has no attribute 'bot'
2024-06-16T23:07:00.043268+00:00 app[web.1]: 2024-06-16 23:07:00,043 - apscheduler.executors.default - INFO - Running job "notify_workday_end_students (trigger: cron[hour='23', minute='7'], next run at: 2024-06-17 23:07:00 UTC)" (scheduled at 2024-06-16 23:07:00+00:00)
2024-06-16T23:07:00.043293+00:00 app[web.1]: Context object: None
2024-06-16T23:07:00.043772+00:00 app[web.1]: Traceback (most recent call last):
2024-06-16T23:07:00.043772+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
2024-06-16T23:07:00.043772+00:00 app[web.1]: retval = await job.func(*job.args, **job.kwargs)
2024-06-16T23:07:00.043773+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-16T23:07:00.043773+00:00 app[web.1]: File "/app/notifications.py", line 36, in notify_workday_end_students
2024-06-16T23:07:00.043773+00:00 app[web.1]: await context.bot.send_message(pwd_group_chat_id, END_WORKDAY_MESSAGE_STUDENTS)
2024-06-16T23:07:00.043773+00:00 app[web.1]: ^^^^^^^^^^^
2024-06-16T23:07:00.043774+00:00 app[web.1]: AttributeError: 'NoneType' object has no attribute 'bot'
I am totally new to python telegram bot and I am trying my best to understand the documentation.
Any help would be really appreciated