获取成员时出错:对 Telegram API 的请求不成功。错误代码:400。描述:错误请求:找不到用户

问题描述 投票:0回答:0

通过命令/all,机器人必须输出组或频道的所有用户的昵称,无论他们的权限如何。但它给出了一个错误:Error getting member: A request to the Telegram API was successful。错误代码:400。说明:错误请求:找不到用户。首先,我使用了 get_chat_administrators 并冷静地给出了所有(添加的管理员的)昵称。可能是什么问题呢?我使用 bibl - pytelegrambotApi.

import telebot

TOKEN = "myTOKEN_ID"
    bot = telebot.TeleBot(TOKEN)  
    @bot.message_handler(content_types=['text', 'photo', 'document', 'video', 'audio', 'location', 'contact', 'sticker'])
        def handle_all_command(message):
            if message.chat.type != "group" and message.chat.type != "supergroup":
                return
            if message.content_type == 'text' and '/all' in message.text.strip().split() or (message.content_type in ['photo', 'document', 'video', 'audio', 'location', 'contact', 'sticker'] and message.caption and '/all' in message.caption.strip().split()):
                is_admin = False
                bot_member = bot.get_chat_member(message.chat.id, bot.get_me().id)
                if bot_member and bot_member.status == "administrator":
                    is_admin = True
                if not is_admin:
                    bot.reply_to(message, "The bot is not configured!")
                    return
                usernames = ""
                members_count = bot.get_chat_members_count(message.chat.id)
                for i in range(members_count):
        
       #######################################
                    try:
                        user = bot.get_chat_member(message.chat.id, i+1)
                        if user.user.username:
                            usernames += "@" + user.user.username + " "
                        elif user.user.first_name:
                            usernames += user.user.first_name + " "
                        elif user.user.last_name:
                            usernames += user.user.last_name + " "
                    except Exception as e:
                        print("Error getting member: ", e)
        #######################################  

                bot.reply_to(message, "Usernames: " + usernames)   
    bot.polling()

一开始我用的是get_chat_administrators,淡定的把昵称都给了出来。可能是什么问题?

python telegram-bot python-telegram-bot py-telegram-bot-api
© www.soinside.com 2019 - 2024. All rights reserved.