Help to troubleshoot error "missing 1 required positional argument: 'context'" #3783
-
Trying to build my first bot and got stuck here. My code: from telegram import Update
from telegram.ext import filters, ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler
import text_module
class Bot():
def __init__(self, config):
# some config value, irrelevant
#update some text every 5 sec
async def start_update(self,update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
context.job_queue.run_repeating(self.update_text, interval=5)
async def update_text(self,update: Update,context: ContextTypes.DEFAULT_TYPE):
#get new text
new_text = text_module.update_text()
await self.process_text(context,new_text)
async def process_text(self, context: ContextTypes.DEFAULT_TYPE,my_text):
# do some text processing here
final_text = text_module.process_text()
await context.bot.send_message(chat_id='my_id',text=final_text)
def run(self):
application = ApplicationBuilder().token('TOKEN')').build()
application.add_handler(CommandHandler('update', self.start_update))
application.run_polling()
if __name__ == '__main__':
tg_bot = Bot(config=config)
tg_bot.run() When I run this script, I got
What does this error mean? I think I still do not fully understand the Callbackcontext in PTB....Could anyone help me out here? Thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
Bibo-Joshi
Jun 30, 2023
Replies: 1 comment 1 reply
Answer selected by
Ayanaminn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Frequently-Asked-Questions#why-am-i-getting-an-error-the-following-arguments-have-not-been-supplied