Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Python
  4. Telegram bot for membership management

Telegram bot for membership management

Scheduled Pinned Locked Moved Python
helpsharepointcomjsonlounge
2 Posts 2 Posters 39 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohamed Sylla 2024
    wrote on last edited by
    #1

    Hello/Good evening everyone, I'm new to the field of programming and have been trying to fill my knowledge gap with AI. My goal is to create a bot that instantly sends a message to a user whenever they request membership to the group the bot is affiliated with. After numerous attempts with the help of AI, I managed to obtain a usable code. Unfortunately, when I run it, nothing happens. Here is the link to my GitHub project: https://github.com/tesbgtoi/ybot If anyone has experience with the Telegram API and could help me identify what's not working or provide advice on fixing my code, I would be extremely grateful. Thank you very much for your help!

    import logging
    from telegram import Bot
    from telegram.error import TelegramError

    Configurez le logging

    logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO
    )
    logger = logging.getLogger(__name__)

    Informations spécifiques

    TOKEN = "TOKEN_DU_BOT"
    GROUP_ID = 123456789 # Remplacez par l'ID de votre groupe

    Fonction pour récupérer les demandes d'adhésion en attente

    async def get_membership_requests(bot: Bot, group_id: int) -> list:
    try:
    administrators = await bot.get_chat_administrators(chat_id=group_id)
    membership_requests = []
    for admin in administrators:
    if not admin.user.is_bot:
    member = await bot.get_chat_member(chat_id=group_id, user_id=admin.user.id)
    if member.status == 'restricted':
    membership_requests.append(member)
    return membership_requests
    except TelegramError as e:
    logger.error(f"Erreur lors de la récupération des demandes d'adhésion : {e}")
    return []

    Fonction pour envoyer des messages aux utilisateurs en attente

    async def send_membership_notifications(bot: Bot, group_id: int, membership_requests: list) -> None:
    for request in membership_requests:
    try:
    await bot.send_message(
    chat_id=request.user.id,
    text="Votre demande d'adhésion au groupe a été reçue. Veuillez patienter pendant que l'administrateur approuve votre demande."
    )
    logger.info(f"Notification envoyée à l'utilisateur : {request.user.id}")
    except TelegramError as e:
    logger.error(f"Erreur lors de l'envoi de la notification à l'utilisateur {request.user.id} : {e}")

    async def main() -> None:
    bot = Bot(token=TOKEN)

    # Récupérer les de
    
    A 1 Reply Last reply
    0
    • M Mohamed Sylla 2024

      Hello/Good evening everyone, I'm new to the field of programming and have been trying to fill my knowledge gap with AI. My goal is to create a bot that instantly sends a message to a user whenever they request membership to the group the bot is affiliated with. After numerous attempts with the help of AI, I managed to obtain a usable code. Unfortunately, when I run it, nothing happens. Here is the link to my GitHub project: https://github.com/tesbgtoi/ybot If anyone has experience with the Telegram API and could help me identify what's not working or provide advice on fixing my code, I would be extremely grateful. Thank you very much for your help!

      import logging
      from telegram import Bot
      from telegram.error import TelegramError

      Configurez le logging

      logging.basicConfig(
      format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
      level=logging.INFO
      )
      logger = logging.getLogger(__name__)

      Informations spécifiques

      TOKEN = "TOKEN_DU_BOT"
      GROUP_ID = 123456789 # Remplacez par l'ID de votre groupe

      Fonction pour récupérer les demandes d'adhésion en attente

      async def get_membership_requests(bot: Bot, group_id: int) -> list:
      try:
      administrators = await bot.get_chat_administrators(chat_id=group_id)
      membership_requests = []
      for admin in administrators:
      if not admin.user.is_bot:
      member = await bot.get_chat_member(chat_id=group_id, user_id=admin.user.id)
      if member.status == 'restricted':
      membership_requests.append(member)
      return membership_requests
      except TelegramError as e:
      logger.error(f"Erreur lors de la récupération des demandes d'adhésion : {e}")
      return []

      Fonction pour envoyer des messages aux utilisateurs en attente

      async def send_membership_notifications(bot: Bot, group_id: int, membership_requests: list) -> None:
      for request in membership_requests:
      try:
      await bot.send_message(
      chat_id=request.user.id,
      text="Votre demande d'adhésion au groupe a été reçue. Veuillez patienter pendant que l'administrateur approuve votre demande."
      )
      logger.info(f"Notification envoyée à l'utilisateur : {request.user.id}")
      except TelegramError as e:
      logger.error(f"Erreur lors de l'envoi de la notification à l'utilisateur {request.user.id} : {e}")

      async def main() -> None:
      bot = Bot(token=TOKEN)

      # Récupérer les de
      
      A Offline
      A Offline
      Akrash Nadeem
      wrote on last edited by
      #2

      Hi, I think i maybe able to help you i have a lot of experience with telegram bots. Although i won't actually help you in coding but i can help you build a logic for you bot.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups