Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Error while coding telegram bot in python

onddyy

Coder
Hello, I am having errors while coding a telegram bot, I get this code by ChatGPT, and it says this error:
Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 28, in main
updater = Updater(TOKEN)
^^^^^^^^^^^^^^
TypeError: Updater.init() missing 1 required positional argument: 'update_queue'

I wanna code an order bot for telegram.







from telegram.ext import Updater, CommandHandler, MessageHandler, filters

TOKEN = 'mytoken'
user_orders = {}

def start(update, context):
update.message.reply_text("Welcome! How can I assist you?")

def order(update, context):
update.message.reply_text("Please enter your order.")

def handle_order(update, context):
user = update.message.from_user
order_text = update.message.text

user_orders[user.id] = order_text
update.message.reply_text(f"Order received: {order_text}. Thank you!")

def show_order(update, context):
user = update.message.from_user
if user.id in user_orders:
order_text = user_orders[user.id]
update.message.reply_text(f"Your order: {order_text}")
else:
update.message.reply_text("You haven't placed an order yet.")

def main():
= Updater(TOKEN)
dp = updater.dispatcher

dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("order", order))
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_order))
dp.add_handler(CommandHandler("show_order", show_order))

updater.start_polling()
updater.idle()

if name == 'main':
main()
 
Hello, I am having errors while coding a telegram bot, I get this code by ChatGPT, and it says this error:
Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 28, in main
updater = Updater(TOKEN)
^^^^^^^^^^^^^^
TypeError: Updater.init() missing 1 required positional argument: 'update_queue'

I wanna code an order bot for telegram.







from telegram.ext import Updater, CommandHandler, MessageHandler, filters

TOKEN = 'mytoken'
user_orders = {}

def start(update, context):
update.message.reply_text("Welcome! How can I assist you?")

def order(update, context):
update.message.reply_text("Please enter your order.")

def handle_order(update, context):
user = update.message.from_user
order_text = update.message.text

user_orders[user.id] = order_text
update.message.reply_text(f"Order received: {order_text}. Thank you!")

def show_order(update, context):
user = update.message.from_user
if user.id in user_orders:
order_text = user_orders[user.id]
update.message.reply_text(f"Your order: {order_text}")
else:
update.message.reply_text("You haven't placed an order yet.")

def main():
= Updater(TOKEN)
dp = updater.dispatcher

dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("order", order))
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_order))
dp.add_handler(CommandHandler("show_order", show_order))

updater.start_polling()
updater.idle()

if name == 'main':
main()
Hi there,

What is the purpose of this bot, if you don't mind me asking?
 
ehmm, I have never coded in Python, sooo, no I dont understand the error
So, this here:

"C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 28, in main

TypeError: Updater.init() missing 1 required positional argument: 'update_queue'

Is telling you that on in file bot.py, the code on line 28, is missing a parameter. This means that Updater(TOKEN), should be something like this

updater = Updater(TOKEN,0)
 
Yea, I fixed line 28, but it has problem with line 29, this is the error:

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 29, in main
dp = updater.dispatcher
^^^^^^^^^^^^^^^^^^
AttributeError: 'Updater' object has no attribute 'dispatcher'
 
Yea, I fixed line 28, but it has problem with line 29, this is the error:

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 29, in main
dp = updater.dispatcher
^^^^^^^^^^^^^^^^^^
AttributeError: 'Updater' object has no attribute 'dispatcher'
Try changing the line from
dp = updater.dispatcher

to this
dp = updater.dispatcher()
 
did that, but doesnt work

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 29, in main
dp = updater.dispatcher(0)
^^^^^^^^^^^^^^^^^^
AttributeError: 'Updater' object has no attribute 'dispatcher'
 
did that, but doesnt work

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 29, in main
dp = updater.dispatcher(0)
^^^^^^^^^^^^^^^^^^
AttributeError: 'Updater' object has no attribute 'dispatcher'
ok, so remove that line, since the error message matches the last message.
 
did that, still doesnt work

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 31, in main
dp.add_handler(CommandHandler("start", start))
^^
NameError: name 'dp' is not defined
 
did that, still doesnt work

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 40, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 31, in main
dp.add_handler(CommandHandler("start", start))
^^
NameError: name 'dp' is not defined
ok, so since dp is needed, that line is necessary. The only thing that concerns me is the fact that Updater doesn't have the call to dispatcher as an attribute... I am thinking it may be a different call. Can you try the following line?

dp = updater.dispatch()
 
still doesnt work, you already said to me to do this

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 41, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 29, in main
dp = updater.dispatch()
^^^^^^^^^^^^^^^^
AttributeError: 'Updater' object has no attribute 'dispatch'
 
still doesnt work, you already said to me to do this

Traceback (most recent call last):
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 41, in <module>
main()
File "C:\Users\ohora\PycharmProjects\TelegramBot\.venv\bot.py", line 29, in main
dp = updater.dispatch()
^^^^^^^^^^^^^^^^
AttributeError: 'Updater' object has no attribute 'dispatch'
ok, so after a bit of digging, it looks like this error was previously recorded on StackOverflow. According to the top answer, it looks like you may need to install a different version of the telegram library the code is using. Are you working on a Windows machine, or Linux machine?
 

New Threads

Buy us a coffee!

Back
Top Bottom