微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 python-telegram-bot 中自动执行禁止命令?

如何解决如何在 python-telegram-bot 中自动执行禁止命令?

我在 Python 领域相对较新(我有 C++ 的概念),我想创建一个自动执行禁令的机器人,只要它检测到俄罗斯机器人的昵称中带有西里尔字母进入组。

我复制粘贴了不同示例的几个部分,但我不知道我是否做得好。代码如下:

import re 
import logging
 
from telegram import ReplyKeyboardMarkup,ReplyKeyboardRemove,Update
from telegram.ext import (
    Updater,CommandHandler,MessageHandler,Filters,ConversationHandler,CallbackContext,)
 
  updater = Updater("<MY-BOT-TOKEN>")
 
    # Get the dispatcher to register handlers
    dispatcher = updater.dispatcher
 
    # on different commands - answer in Telegram
    dispatcher.add_handler(CommandHandler("start",start))
    dispatcher.add_handler(CommandHandler("help",help_command))
 
    # on noncommand i.e message - echo the message on Telegram
    dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command,echo))
 
    def has_cyrillic(text):
    return bool(re.search('[а-яА-Я]',text))
 
    def add_group(update: Update,context: CallbackContext):
        for member in update.message.new_chat_members:
            if has_cyrillic(member.full_name):
                --- SUPPOSEDLY,AUTO BAN WOULD BE HERE ---
                update.message.reply_text("{member.full_name} has been banned")
            else:
                update.message.reply_text("{member.full_name} just joined the group")
 
    add_group_handle = MessageHandler(Filters.status_update.new_chat_members,add_group)
 
    # Start the Bot
    updater.start_polling()
 
    # Run the bot until you press Ctrl-C or the process receives SIGINT,# SIGTERM or SIGABRT. This should be used most of the time,since
    # start_polling() is non-blocking and will stop the bot gracefully.
    updater.idle()

我使用的是最新版本的 Python 和 python-telegram-bot。

提前致谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。