I try to make a telegram bot with using VSCode. My telegram bot code is
from telegram.ext import Updater, CommandHandler, MessageHandler, filters
import requests
texts = {"a": "", "b": "", "c": ""}
def start(update, context):
update.message.reply_text('Hello! Send /set a, b, or c followed by the text to set.')
def set_text(update, context):
try:
key = context.args[0]
text = " ".join(context.args[1:])
if key in texts:
texts[key] = text
update.message.reply_text(f'Text for {key} set to: {text}')
# HTTP POST request to C# application
url = "http://localhost:5000/settext"
payload = {"key": key, "text": text}
requests.post(url, data=payload)
else:
update.message.reply_text('Invalid key. Use a, b, or c.')
except IndexError:
update.message.reply_text('Usage: /set [a|b|c] [text]')
def main():
updater = Updater("TOKEN", use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("set", set_text))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
I got an error when try to start bot. Python version is 3.12.0 python-telegram-bot version is 21.3
Error :
Traceback (most recent call last):
File "E:UsersSLapsourcereposCrypTechToolCrypTechToolbinDebugnet6.0-windowstelegrambot.py", line 37, in <module>
main()
File "E:UsersSLapsourcereposCrypTechToolCrypTechToolbinDebugnet6.0-windowstelegrambot.py", line 27, in main
updater = Updater("TOKEN", use_context=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Updater.__init__() got an unexpected keyword argument 'use_context'
Can you help me anyone ? I use ChatGPT and search on google. No result
I want to start this bot but i got an error when i try to start.
New contributor
CaptainSLap is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.