Create Your Own Telegram Profile Card Bot! | Master the Magic of Python with @TraxDinosaur

 

Telegram Profile Card Bot

 



 Code:
'''
CARD MAKER TG BOT TUTORIAL
GitHub: TraxDinosaur
Replit: TraxDinosaur
Instagram: @TraxDinosaur
YouTube: @TraxDinosaur
Blogger: TraxDinosaurs
'''
# Logging
import logging
from telegram import Update
from PIL import Image, ImageOps, ImageDraw, ImageFont
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler
# Logging Config
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
# Commands
async def start(update:Update, context:ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id,text="Welcome To The Card Generator Bot!\n Please Use /help To Learn How To Use Me")
async def help(update:Update, context:ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id,text="To Generate Card Use Command /card .")
async def gencard(update:Update, context:ContextTypes.DEFAULT_TYPE):
generate_text = update.message.from_user.full_name
card = Image.open('telegram.jpg')
draw = ImageDraw.Draw(card)
font = ImageFont.truetype('arial.ttf',20)
draw.text((243,392),generate_text, fill='black',font=font)
card.save('card.jpg')
await context.bot.send_photo(chat_id=update.effective_chat.id,photo=open('card.jpg','rb'))
print("Bot Is Working")
if __name__ == "__main__":
app = ApplicationBuilder().token("YOUR_BOT_TOKEN").build()
# Handlers
start_handler = CommandHandler('start', start)
app.add_handler(start_handler)
help_handler = CommandHandler('help', help)
app.add_handler(help_handler)
card_handler = CommandHandler('card',gencard)
app.add_handler(card_handler)
app.run_polling()
view raw CardGenBot.py hosted with ❤ by GitHub
 

Post a Comment

0 Comments