Notice
Recent Posts
Recent Comments
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

아직도 텔레그램 안쓰니?

텔레그램 봇 나만 사용하기 본문

텔레그램 팁

텔레그램 봇 나만 사용하기

텔레그램사랑 2024. 1. 4. 13:13

텔레그램 봇은 비공개가 안된다

그래서 나만 사용하려고 만든 봇이 다른 사람들도 검색해서 사용할 수 있다

그걸 방지하려면 내 chat id를 확인하고 동작하게 하면 된다

 

 

from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler

TOKEN = "토큰"
CHAT_ID = "챗아이디"

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
	# chat id를 확인한다.
    if update.effective_chat.id == CHAT_ID:
        await context.bot.send_message(chat_id=update.effective_chat.id, text="내꺼야")
    else:
        await context.bot.send_message(chat_id=update.effective_chat.id, text="꺼져라")

if __name__ == "__main__":
    application = ApplicationBuilder().token(TOKEN).build()

    start_handler = CommandHandler("start", start)
    application.add_handler(start_handler)

    application.run_polling()