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

사이트 내 전체검색

로그인
회원가입
IT Tip&Tech

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

페이지 정보

View1,410  | 작성일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 목록

게시물 검색

Copyright © LittleCandle All rights reserved.
문의메일 : littlecandle99@gmail.com
PC 버전으로 보기