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.
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 ) 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
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 ) 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
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.