간단한 /start 명령어에 반응하는 텔레그램 봇 만들기 > IT Note

본문 바로가기
사이트 내 전체검색

로그인
회원가입
IT Note

간단한 /start 명령어에 반응하는 텔레그램 봇 만들기
0

View 1,409  | 작성일2023.03.20 23:34

본문

https://littlecandle.co.kr/bbs/board.php?bo_table=codingnote&wr_id=298 

요기 까지 되신다면 이글대로 하시면 됩니다.


결국 제대로된 한글정보가 없어서 

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot 

깃허브 공식문서를 참조하고 있습니다... 어쩔수 없죠.. 공식문서를 보는게 제일 빠르긴 하지..


여튼 공식문서의 샘플코드는 다음과 같습니다.

 import logging

from telegram import Update

from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler


logging.basicConfig(

    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',

    level=logging.INFO

)


async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):

    await context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")


if __name__ == '__main__':

    application = ApplicationBuilder().token('토큰번호').build()

    

    start_handler = CommandHandler('start', start)

    application.add_handler(start_handler)

    

    application.run_polling()


요거대로 하면 ctrl+c 눌러서 파이썬 프로그램이 종료 될때 까지는 /start 명령어에 반응하여 텍스트를 찍어줍니다.

댓글목록

등록된 댓글이 없습니다.

IT Tip&Tech 목록

게시물 검색

접속자집계

오늘
964
어제
905
최대
6,399
전체
671,612
Copyright © LittleCandle All rights reserved.
문의메일 : littlecandle99@gmail.com
모바일 버전으로 보기