아직도 텔레그램 안쓰니?
텔레그램 봇 나만 사용하기 본문
텔레그램 봇은 비공개가 안된다
그래서 나만 사용하려고 만든 봇이 다른 사람들도 검색해서 사용할 수 있다
그걸 방지하려면 내 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()
'텔레그램 팁' 카테고리의 다른 글
텔레그램 봇으로 스티커 보내기 (0) | 2024.01.07 |
---|---|
텔레그램 봇 ReplyKeyboardMarkup 버튼 코드 (0) | 2024.01.04 |
새로 찾은 텔레그램 채널 검색 사이트 (18) | 2024.01.03 |
텔레그램 봇 Telethon 라이브러리 명령어 코드 (1) | 2024.01.02 |
텔레그램 봇 커맨드 추가하기 (0) | 2023.12.30 |