Create create_invite_link.py

Added create_chat_invite_link() func example
This commit is contained in:
Advik Singh Somvanshi 2022-05-20 23:00:38 +05:30 committed by GitHub
parent 7567750276
commit 8fefd7b5b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import telebot, threading
from time import sleep, time
from telebot import InlineKeyboardMarkup as ikm #Only for creating Inline Buttons, not necessary for creating Invite Links
from telebot import InlineKeyboardButton as ikb #Only for creating Inline Buttons, not necessary for creating Invite Links
Token = "api_token" #Your Bot Access Token
Group_ID = -1234567890 #Group ID for which invite link is to be created
bot = telebot.TeleBot(Token, parse_mode="HTML")
#/start command message
@bot.message_handler(commands=['start'])
def startmsg(msg):
bot.reply_to(msg, "Hey there, I'm a bot made by pyTelegramBotAPI!")
#Get notified of incoming members in group
@bot.message_handler(content_types=['new_chat_members'])
def newmember(msg):
#Create an invite link class that contains info about the created invite link using create_chat_invite_link() with parameters
invite = bot.create_chat_invite_link(Group_ID, member_limit=1, expire_date=int(time())+45) #Here, the link will auto-expire in 45 seconds
InviteLink = invite.invite_link #Get the actual invite link from 'invite' class
mrkplink = ikm() #Created Inline Markup Keyboard
mrkplink.add(ikb("Join our group 🚀", url=InviteLink)) #Added Invite Link to Inline Markup Keyboard
bot.send_message(msg.chat.id, f"Hey there {msg.from_user.first_name}, Click the link below to join our Official Group." reply_markup=mrkplink)
#This will send a message with the newly-created invite link as markup button.
#The member limit will be 1 and expiring time will be 45 sec.
while True:
try:
bot.infinity_polling()
except:
sleep(0.04)