I want to add to my bot the ability to activate in a chat and have the bot immediately scan all the participants inside. As a result, the code gives an error and is not activated in the chat. Tell me what to do
below is the code and error
user_data = {}
with open('languages.json', 'r', encoding='utf-8') as file:
translations = json.load(file)["translations"]
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = update.message.from_user.id
if user_id not in user_data:
user_data[user_id] = {
'selected_artists': [],
'language': 'ru'
}
await update.message.reply_text(get_translation(user_id, 'start'))
async def activate(update: Update, context: CallbackContext):
chat_id = update.message.chat_id
user_status = await context.bot.get_chat_member(chat_id, update.message.from_user.id)
if user_status.status not in ['administrator', 'creator']:
await update.message.reply_text("Only administrators can use this command.")
return
chat_members = await context.bot.get_chat_members(chat_id)
if 'chat_users' not in user_data:
user_data['chat_users'] = {}
for member in chat_members:
user_data['chat_users'][member.user.id] = chat_id
await update.message.reply_text("Bot has been activated for all users in this chat.")
Error:
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "C:UsersDmitriAppDataLocalProgramsPythonPython312Libsite-packagestelegramext_application.py", line 1325, in process_update
await coroutine
File "C:UsersDmitriAppDataLocalProgramsPythonPython312Libsite-packagestelegramext_handlersbasehandler.py", line 157, in handle_update
return await self.callback(update, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:UsersDmitriDesktoptelegrambotChartMakerTop.py", line 44, in activate
chat_members = await context.bot.get_chat_members(chat_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ExtBot' object has no attribute 'get_chat_members'. Did you mean: 'get_chat_member'?
I tried to fix it in other ways, but nothing worked. I want the bot to scan all chat users after the /activate command and save them in the user_data array
New contributor