无法使用 python telegram bot 踢聊天成员

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

我正在尝试使用“context.bot.kick_chat_member”实现自踢命令 但是,它给出了错误: AttributeError:“ExtBot”对象没有属性“kick_chat_member”

这是我的代码:

async def Z(update, context):
    await context.bot.kick_chat_member(chat_id=update.effective_chat.id, user_id=update.effective_user.id, timeout=int(time.time() + 86400)) # expiry after 24h

if __name__ == '__main__':
    
    application = ApplicationBuilder().token(TOKEN).build()
    
    start_handler = CommandHandler('start', start)
    application.add_handler(start_handler)
    
    application.add_handler(CallbackQueryHandler(callback_query_handler))
    
    # Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
    conv_handler = ConversationHandler(
        entry_points=[CommandHandler("image", image)],
        states={
            GENDER: [MessageHandler(filters.Regex("^(Art|Anime|Hent)$"), gender)],
            PHOTO: [MessageHandler(filters.PHOTO, photo), CommandHandler("skip", skip_photo)],
            BIO: [MessageHandler(filters.TEXT & ~filters.COMMAND, bio)],
        },
        fallbacks=[CommandHandler("cancel", cancel)],
    )

    application.add_handler(conv_handler)

    application.add_handler(CommandHandler('Z', Z))
   
    application.run_polling()

注意:其他 context.bot 命令正在运行,例如:

await context.bot.send_message(chat_id=update.effective_chat.id, text= str(update.effective_user.first_name) + ", hello")
await context.bot.delete_message(chat_id=update.effective_chat.id, message_id=messages[i])

我在努力 context.bot.kick_chat_member(chat_id=update.effective_chat.id, user_id=update.effective_user.id, timeout=int(time.time() + 86400))

那没有用,我希望有人建议使用哪种方法来让机器人踢成员或如何让 context.bot.kick_chat_member 工作。

python python-telegram-bot
1个回答
0
投票

库版本20+没有使用此方法。

版本 20.0 中的更改:

删除了弃用的方法 kick_chat_member、kickChatMember、get_chat_members_count 和 getChatMembersCount。

以这种方式尝试(您可以在这里看到参数):

await update.chat_member.chat.ban_member(user_id=user_id)
© www.soinside.com 2019 - 2024. All rights reserved.