I have been trying to run this code but this is the output

Please don’t post screenshots.

Copy and paste any code or traceback, and in order to preserve formatting, select the code or traceback that you posted and then click the </> button.

As you haven’t posted the code, I’m going to have to guess from the tracback that you left out self when you defined the __init__ method of the Updater class.

2 Likes

Traceback (most recent call last):
File “C:/Python/Python311/Constants.py”, line 2, in
import Constants as Keys
File “C:\Python/Python311\Constants.py”, line 35, in
main()
File “C:\Python/Python311\Constants.py”, line 25, in main
updater = Updater(myBot)
TypeError: Updater.init() missing 1 required positional argument: ‘update_queue’

Please post the code if the error is not obvious to you.

You have posted that code in text before (I SAW IT :wink: ) Now you are doing the bad thing™ again with a screenshot. Please don’t do that. The code is meant to be read not admired in a picture :stuck_out_tongue:

1 Like

This is the code

from telegram import Bot
import Constants as Keys
from telegram.ext import *
import Responses as R
from datetime import datetime
print(‘Bot started…’)
def start_command(Update,context ):
update.message.reply_text(‘Type something random to get started’)

def help_command(UpdUpdate,context ):
update.message.reply_text(‘If you need help! you should ask for it on google!’)
def handle_message(Update,context ):
text = str(update.message.text).lower()
response = R.sample_response(text)
update.message.reply_text(response)
def error(update,context):
print(f"update{update} caused error{context.error}")

def main():
myBot = Bot('’)
updater = Updater(myBot)
dp = updater.dispatcher
dp.add_handler(CommandHandler(‘start’,start_command))
dp.add_handler(CommandHandler(‘start’,help_command))
dp.add_handler(MessageHandler(filters.Text,help_command))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

main()

Good, now fence your code with ``` (that are 3 backticks), because as your see the forum’s software mangled it

Ok better, but its not pre-formatted text yet.

See this for host to post code: About the Python Help category

Please edit the post so that it is pre-formatted text.

#This the code

from telegram import Bot
import Constants as Keys
from telegram.ext import *
import Responses as R
from datetime import datetime
print(‘Bot started…’)
def start_command(Update,context ):
update.message.reply_text(‘Type something random to get started’)

def help_command(UpdUpdate,context ):
update.message.reply_text(‘If you need help! you should ask for it on google!’)
def handle_message(Update,context ):
text = str(update.message.text).lower()
response = R.sample_response(text)
update.message.reply_text(response)
def error(update,context):
print(f"update{update} caused error{context.error}")

def main():
myBot = Bot(‘’)
updater = Updater(myBot)
dp = updater.dispatcher
dp.add_handler(CommandHandler(‘start’,start_command))
dp.add_handler(CommandHandler(‘start’,help_command))
dp.add_handler(MessageHandler(filters.Text,help_command))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
main()

Better. But it seems you copy-pasted the mangled code from the previous post. In Python indentations are important, so please, edit (remember! you can edit your posts :slight_smile: ) your post so indentations are in the right places.

If you ask why all that “circus” is about, then I’m explaining: Imagine that you are a doctor and once a mom comes to you and tells you that her son probably dislocated his elbow. You say you want to see the son, and the mother does right that…by showing you an image of her son in her mobile :smiley:

If you can tell what’s wrong in my so-so story, they you will know what is our (me and other people on this forum) problem with helping you.


from telegram import Bot
import Constants as Keys
from telegram.ext import *
import Responses as R
from datetime import datetime
print('Bot started...')
def start_command(Update,context ):
    update.message.reply_text('Type something random to get started')

def help_command(Update,context ):
    update.message.reply_text('If you need help! you should ask for it on google!')
    

def handle_message(Update,context ):
    text = str(update.message.text).lower()
    response = R.sample_response(text)

    update.message.reply_text(response)

def error(update,context):
    print(f"update{update} caused error{context.error}")

def main():
    myBot = Bot()
    updater = Updater(myBot)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler('start',start_command))
    dp.add_handler(CommandHandler('start',help_command))
    dp.add_handler(MessageHandler(filters.Text,help_command))
    dp.add_error_handler(error)

    updater.start_polling()
    updater.idle()

main() 
    ```

Thank you.

I’m guessing that you’re using python-telegram-bot, docs here:
https://docs.python-telegram-bot.org/en/v21.0.1/

If not, let us know.

To recap, your exception traceback looked like this:

 Traceback (most recent call last):
   File "C:/Python/Python311/Constants.py", line 2, in <module>
     import Constants as Keys
   File "C:\Python/Python311\Constants.py", line 35, in <module>
     main()
   File "C:\Python/Python311\Constants.py", line 25, in main
     updater = Updater(myBot)
 TypeError: Updater.__init__() missing 1 required positional argument: 'update_queue'

which says that your call of Updater(myBot) is missing an argument. So
let’s look at the docs for Updater
which says, matching the error, that is needs both a bot and an
update_queue, which is an asyncio.Queue.

It looks like you can just allocate one of these (which makes me wonder
why the Updater class won’t do that for you, but no matter), so maybe
do this:

 from asyncio import Queue

in the imports and modify your bot setup to be like this:

 myBot = Bot()
 botQueue = Queue()
 updater = Updater(myBot, botQueue)

and see what happens then. Disclaimer: I’ve never used the telegram
libraries before.

1 Like