You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python Telegram Bot实现踢人功能报错:'ExtBot'无kick_chat_member属性

解决AttributeError: 'ExtBot' object has no attribute 'kick_chat_member'问题

你遇到的问题是因为使用的python-telegram-bot v20及以上版本已弃用kick_chat_member方法,取而代之的是ban_chat_member,同时参数也做了调整:

  • 原timeout参数替换为until_date,作用一致,用于指定封禁到期的时间戳

修改后的自踢命令代码如下:

import time

async def Z(update, context):
    # 设置24小时后自动解封
    until_date = int(time.time()) + 86400
    await context.bot.ban_chat_member(
        chat_id=update.effective_chat.id,
        user_id=update.effective_user.id,
        until_date=until_date
    )

额外注意事项

  • 机器人必须在目标群组/超级群组中拥有封禁用户的权限,否则会返回权限错误
  • 自踢功能存在限制:如果用户是群组创建者,或用户的管理员权限高于机器人,机器人无法执行封禁操作
  • 若需保留旧版方法名,可降级到python-telegram-bot v13.x版本,但官方推荐使用最新版以获得功能更新和bug修复

内容的提问来源于stack exchange,提问作者Artem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 08:22:03