I have this working code:
from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext
updater = Updater('token')
def hello(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Hello!')
updater.dispatcher.add_handler(CommandHandler('hello', hello))
updater.start_polling()
updater.idle()
I wish to have a separate file for each function and have a main.py where I import them.
So I head to create a f1.py with just this:
def hello(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Hello!')
Then import it into a main.py with
from f1 import hello
hello()
Obviously, this is not working (missing arguments). How do I do it correctly?
2
Answers
For more informations, here is a good source for import own modules:
https://docs.python.org/3/tutorial/modules.html
Your
main.py
andf1.py
are fine, but onupdater.dispatcher
of yourmain.py
something is missing. Try this:Try this and let me know if it worked for you!