Telethon client.conversation() 不起作用

我尝试使用电视马拉松与电报机器人进行类似测验的对话。它应该看起来像:


user1 > /start

bot > Hello who send you?

user1 > user0

bot > Thank you. So do you want in channel1 or channel2 or both?

user1 > channel1

*Bot invites the user

我使用了这个例子: https://arabic-telethon.readthedocs.io/en/stable/extra/examples/telegram-client.html#conversations-waiting-for-messages-or-replies 示例代码:


with bot.conversation(chat) as conv:

    conv.send_message('Hi!')

    hello = conv.get_response()


    conv.send_message('Please tell me your name')

    name = conv.get_response().raw_text

    while not any(x.isalpha() for x in name):

        conv.send_message("Your name didn't have any letters! Try again")

        name = conv.get_response().raw_text


    conv.send_message('Thanks {}!'.format(name))

但它不会运行。文档中写道,聊天代表一个实体。所以我尝试了发件人 ID 和用户名...


我的代码:


@bot.on(events.NewMessage(chats=bot.get_entity('Just Another Test Group'),blacklist_chats=True,pattern='/access'))

async def access(event):

    print("jop")

    temp = await event.get_sender()

    temp2 = await event.get_chat()

    print(temp)

    print(temp2.id)

    with bot.conversation(temp.id) as conv:

        print("started")

        event.respond("hmm")

        conv.send_message('Hi!')

        hello = conv.get_response()


        conv.send_message('Please tell me your name')

        name = conv.get_response().raw_text

        while not any(x.isalpha() for x in name):

            conv.send_message("Your name didn't have any letters! Try again")

            name = conv.get_response().raw_text


        conv.send_message('Thanks {}!'.format(name))


人到中年有点甜
浏览 70回答 1
1回答

幕布斯6054654

天啊……对不起。这是关于 Telegram Web 的。当我使用手机或桌面应用程序时,我会完美地重新排列所有内容......我对此感到抱歉。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python