@bot.message_handler(commands=['start'])
def welcome(message):
sti = open('imagine/sticker.webp', 'rb')
bot.send_sticker(message.chat.id, sti)
#КЛАВИАТУРА 1
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
item = types.KeyboardButton("\N{world map}")
markup.add(item)
bot.send_message(message.chat.id, "Привет! /help".format(message.from_user,bot.get_me()),
parse_mode='html', reply_markup=markup)
@bot.message_handler(commands=['help'])
def hi1(message):
bot.send_message (message.chat.id, "Наберите команду /go или /we")
@bot.message_handler(commands=['go'])
def go(message):
#КЛАВИАТУРА 2
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
item1 = types.KeyboardButton("\N{baby}")
item2 = types.KeyboardButton("\N{girl}")
item3 = types.KeyboardButton("\N{man}")
markup.add(item1, item2, item3)
bot.send_message(message.chat.id, "Возраст?", reply_markup=markup)
bot.register_next_step_handler(go1)
@bot.message_handler(content_types=['text'])
def hi(message):
if message.chat.type == 'private':
if message.text == '\N{world map}':
mesg = bot.send_message(message.chat.id, 'наберите команду /go')
if message.text == '/go':
bot.register_next_step_handler(mesg, go)
else:
bot.send_message(message.chat.id, 'Не знаю, что и ответить \N{anguished face} \nНабери команду /help, чтобы ознакомиться со списком команд')
def go1(message):
if message.chat.type == 'private':
if message.text == '\N{baby}':
#КЛАВИАТУРА 3
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
item1 = types.KeyboardButton("игры")
item2 = types.KeyboardButton("деньги")
item3 = types.KeyboardButton("телки")
markup.add(item1, item2, item3)
bot.send_message(message.chat.id, 'Окей, кого вы любите больше?')
bot.polling()
если у вас webHook? @server.route('/secrettoken/')
, а не @server.route('/secrettoken')
server.run
в паре с секретным ключом.@bot.message_handler(commands=['roulete'])
def send_rulet(message):
us_id = str(message.chat.id) # или integer, смотря какой тип используется в базе данных
cursor.execute('SELECT coins FROM users WHERE user_id = “' +us_id+'“') # защита от инъекций не нужна, потому что от телеграма не может поступить инъекция
coins = str(cursor.fetchone())
cursor.execute("SELECT * FROM 'users' WHERE 'user_id'='" + us_id + "'")
info = cursor.fetchone()
if info is None:
bot.send_message(message.chat.id, "Используйте /login")
else:
while True:
try:
bot.polling()
except:
continue
bot.polling()
нужно добавить любой другой метод запускающий long polling, если в скрипте используется библиотека альтернативная PyTelegramBotAPI await bot.forward_message(chat_id=<чат id КУДА ПЕРЕСЛАТЬ СООБЩЕНИЕ>, from_chat_id=<чат id ГДЕ БЫЛО ОТПРАВЛЕНО СООБЩЕНИЕ>, message_id<id сообщения>)
import pyshorteners
import os
import platform
import qrcode
class URL():
action = int(input(" What to do? (1.QrCode 2.ShortUrl) "))
def short_url():
url = input(" URL: ")
n = input(" Choice service ( 1:Os.db, 2:Chilp.it, 3:Da.gd, 4:Is.gd, 5:Qps.ru, 6:TinyURL.com): ")
if n == str(1):
s = pyshorteners.Shortener()
f = s.osdb.short(url)
print(" Short URL: ",f)
elif n == str(2):
s = pyshorteners.Shortener()
short_url = s.chilpit.short(url)
print(" Short URL: ",short_url)
elif n == str(3):
s = pyshorteners.Shortener()
abz = s.dagd.short(url)
print(" Short URL: ",abz)
elif n == str(4):
s = pyshorteners.Shortener()
abv = s.isgd.short(url)
print(" Short URL: ",abv)
elif n == str(5):
s = pyshorteners.Shortener()
abh = s.qpsru.short(url)
print(" Short URL: ",abh)
elif n == str(6):
s = pyshorteners.Shortener()
abk = s.tinyurl.short(url)
print(" Short URL: ",abk)
else:
print(' Error ')
def qr_code():
URL = input(" URL: ")
file = input(" Enter file name:")
filename = file +".png"
img = qrcode.make(URL)
img.save(filename)
if action == 1:
qr_code()
elif action == 2:
short_url()
else:
print(" Error ")
<b> это жирный текст </b>
<u> это подчеркнутый текст </u>
import telebot
token = 'TOKEN'
channel_name = '@CHANNEL'
bot = telebot.TeleBot(token)
@bot.message_handler(content_types=['text', 'audio'])
def send_message_group(message):
doc_id = message.audio.file_id
bot.send_audio(channel_name, audio=doc_id, caption=message.text, parse_mode='HTML')
print(f'\nСообщение успешно доставлено.\nText: {message.text}\nFile_Id: {doc_id}')
if __name__ == '__main__':
bot.infinity_polling()
# При этом message.text должен быть составлен так "Это обычный шрифт <b> а тут уже жирный шрифт </b> тут снова обычный <u> а тут подчеркнутый текст </u>"
def deffers():
cursor.execute('SELECT obshee_1 FROM tablica')
knopach1 = cursor.fetchone()
cursor.execute('SELECT obshee_2 FROM tablica')
knopach2 = cursor.fetchone()
klava = types.InlineKeyboardMarkup()
button1=types.InlineKeyboardButton(text='Всего: '+knopach1[0], callback_data='knopka1')
button2=types.InlineKeyboardButton(text='Всего: '+knopach2[0], callback_data='knopka2')
bot.send_message(message.text, 'Ваше абсолютно любое сообщение. Абсолютно любое.', reply_markup=klava)