Telegram bot for membership management
-
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 TelegramErrorConfigurez 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 groupeFonction 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
-
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 TelegramErrorConfigurez 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 groupeFonction 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
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.