1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Unable to display a message to user in telegram bot when a condition is turns false

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I'm working on a Telegram bot using Pyrogram and MongoDB to manage referrals. The function referal_add_user is supposed to prevent users from referring themselves by sending a warning message. However, the bot is not sending this message and is responding with a default message instead.

    Code snippet (file:database.users_chats_db)

    async def referal_add_user(user_id, ref_user_id):
    if user_id == ref_user_id:
    try:
    await client.send_message(
    chat_id=user_id,
    text="⚠️ You can't refer yourself, Send the referral link to your friends."
    )
    except Exception as e:
    print(f"Error sending message: {e}")
    return False

    user_db = mydb[str(user_id)]
    user = {'_id': ref_user_id}
    try:
    user_db.insert_one(user)
    return True
    except DuplicateKeyError:
    return False


    Problem:

    The warning message for self-referral is not being sent.

    Instead, the bot responds with a default message.

    Code snippet (file: Commands.py)

    data = message.command[1]

    if data.split("-", 1)[0] == "VJ":

    user_id = int(data.split("-", 1)[1])

    vj = await referal_add_user(user_id, message.from_user.id)

    if vj and PREMIUM_AND_REFERAL_MODE == True:

    await message.reply(f"<b>You have joined using the referral link of user with ID {user_id}\n\nSend /start again to use the bot</b>")


    Now this is another snippet which is getting displayed properly, I know it's in another file, so if I need to display it here. How can I do that?.

    from pyrogram import Client


    I have added client in database user chat db file and rest. I'm not sure what should I even look for.

    I have tired chatgpt but now much help the bot is deploying perfectly but just not responding

    Continue reading...

Compartilhe esta Página