我尝试使用电视马拉松与电报机器人进行类似测验的对话。它应该看起来像:
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))
幕布斯6054654
相关分类