2017-10-18 4 views
0

전보에 replace 기능을 사용하는 방법을 배우려고합니다. 이를 위해, 먼저 사용자가 말하는 것을 반복하는 기본 봇에서 작동하도록 만들고 있습니다. 따라서 봇은 사용자 메시지의 문자를 대체해야하지만 작동하지 않습니다. 이 예제에서는 메시지를 "o"로 모든 "i"를 대체하도록 봇을 시도하지만 작동하지 않는 것 같습니다.Telegram의 기능 바꾸기

def handle(msg): 
    content_type, chat_type, chat_id = telepot.glance(msg) 
    print(content_type, chat_type, chat_id) 


    if content_type == 'text': 
     msg['text'].replace("i", "o") 
     bot.sendMessage(chat_id, msg['text']) 

답변

0

replace 함수의 반환 결과, 시도 : 그것은 지금 일하고있어

def handle(msg): 
    content_type, chat_type, chat_id = telepot.glance(msg) 
    print(content_type, chat_type, chat_id) 


    if content_type == 'text': 
     msg['text'] = msg['text'].replace("i", "o") 
     bot.sendMessage(chat_id, msg['text']) 
+0

! 고맙습니다. @SatanDmytro – Sile