@Vadim235

Нужно перенести код с telebot на aiogram?

import telebot
from telebot import types

bot = telebot.TeleBot('')

@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Приобрести голду")
btn2 = types.KeyboardButton("☄️ Отзывы")
btn3 = types.KeyboardButton("inline")
btn5 = types.KeyboardButton(" Тех поддержка")
btn6 = types.KeyboardButton(" Профиль")
markup.add(btn1, btn2, btn3, btn5, btn6)
chat_id = message.chat.id
photo = open(r"C:\Users\Вадим\Downloads\msg5595864732-30890.jpg", 'rb')
bot.send_photo(chat_id, photo=photo, caption='Добро пожаловать! \nесли обнаружены ошибки или вопросы - напишите @unponcka \n\n⚔используйте меню для взаимодействия с ботом', reply_markup=markup)

@bot.message_handler(content_types=['text'])
def func(message):
if (message.text == "☄️ Отзывы"):
markup = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton(text='Перейти', url='hm/q/1247696?ysclid=lhagk8lb89664932061')
markup.add(btn1)
chat_id = message.chat.id
photo = open(r"C:\Users\Вадим\Downloads\otz.jpg", 'rb')
bot.send_photo(chat_id, photo=photo, caption='Наш канал с отзывами.', reply_markup=markup)

elif (message.text == " В Главное меню"):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
button1 = types.KeyboardButton("Приобрести голду")
button2 = types.KeyboardButton("☄️ Отзывы")
button3 = types.KeyboardButton("inline")
button4 = types.KeyboardButton(" Тех поддержка")
button5 = types.KeyboardButton(" Профиль")
markup.add(button1, button2, button3, button4, button5)
bot.send_message(message.chat.id, text="Вы вернулись в главное меню.", reply_markup=markup)
if (message.text == " Тех поддержка"):
markup = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton(text='Написать', url='t.me/')
markup.add(btn1)
chat_id = message.chat.id
photo = open(r"C:\Users\Вадим\Downloads\tex.jpg", 'rb')
bot.send_photo(chat_id, photo=photo, caption=' Наша тех поддержка, задайте конкретный вопрос, время ответа 10-20 минут.', reply_markup=markup)
if (message.text == "inline"):
markup = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton(text='Наш сайт', url='https://www.youtube.com/watch?v=xFoUNDRVBYM')
btn2 = types.InlineKeyboardButton(text='Сработает?', callback_data="price_1")
markup.add(btn1, btn2)
bot.send_message(message.chat.id, "Нажми на кнопку и перейди на наш сайт.", reply_markup=markup)
if (message.text == " Профиль"):
bot.send_message(message.chat.id, f'Имя: {message.from_user.first_name} \nID: {message.from_user.id} \nБаланс: ')
elif (message.text == "Приобрести голду"):
message = bot.send_message(message.chat.id, "Введите сумму в рублях: ")
bot.register_next_step_handler(message, start_2)

def start_2(message):
bot.send_message(message.chat.id,
f' Сумма: {int(message.text)} \n Вы получите: {int(message.text) / round(0.65, 2)} золота' '\n\nВыберите удобный способ оплаты:')

@bot.callback_query_handler(func=lambda call: True)
def callback(call):
if call.message:
if call.data == 'price_1':
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.id, text='Сработало!')

bot.polling(none_stop=True)
  • Вопрос задан
  • 161 просмотр
Пригласить эксперта
Ответы на вопрос 1
@Scream034
Новичок в разработке
Я не переписовал, лишь авто.
import logging
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor

# Устанавливаем уровень логов
logging.basicConfig(level=logging.INFO)

# Создаем бота
bot = Bot(token='YOUR_TOKEN_HERE')

# Создаем диспетчер
dp = Dispatcher(bot)

# Обработка команды /start
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    btn1 = types.KeyboardButton("Приобрести голду")
    btn2 = types.KeyboardButton("☄️ Отзывы")
    btn3 = types.KeyboardButton("inline")
    btn5 = types.KeyboardButton(" Тех поддержка")
    btn6 = types.KeyboardButton(" Профиль")
    markup.add(btn1, btn2, btn3, btn5, btn6)
    chat_id = message.chat.id
    photo = open(r"C:\Users\Вадим\Downloads\msg5595864732-30890.jpg", 'rb')
    await bot.send_photo(chat_id, photo=photo, caption='Добро пожаловать! \nесли обнаружены ошибки или вопросы - напишите @unponcka \n\n⚔используйте меню для взаимодействия с ботом', reply_markup=markup)

# Обработка текстовых сообщений
@dp.message_handler(content_types=['text'])
async def handle_text(message: types.Message):
    if message.text == "☄️ Отзывы":
        markup = types.InlineKeyboardMarkup()
        btn1 = types.InlineKeyboardButton(text='Перейти', url='https://qna.habr.com/q/1247696?ysclid=lhagk8lb8966...')
        markup.add(btn1)
        chat_id = message.chat.id
        photo = open(r"C:\Users\Вадим\Downloads\otz.jpg", 'rb')
        await bot.send_photo(chat_id, photo=photo, caption='Наш канал с отзывами.', reply_markup=markup)
    elif message.text == " В Главное меню":
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        button1 = types.KeyboardButton("Приобрести голду")
        button2 = types.KeyboardButton("☄️ Отзывы")
        button3 = types.KeyboardButton("inline")
        button4 = types.KeyboardButton(" Тех поддержка")
        button5 = types.KeyboardButton(" Профиль")
        markup.add(button1, button2, button3, button4, button5)
        await bot.send_message(message.chat.id, text="Вы вернулись в главное меню.", reply_markup=markup)
    elif message.text == " Тех поддержка":
        markup = types.InlineKeyboardMarkup()
        btn1 = types.InlineKeyboardButton(text='Написать', url='t.me/')
        markup.add(btn1)
        chat_id = message.chat.id
        photo = open(r"C:\Users\Вадим\Downloads\tex.jpg", 'rb')
        await bot.send_photo(chat_id, photo=photo, caption=' Наша тех поддержка, задайте конкретный вопрос, время ответа 10-20 минут.', reply_markup=markup)
    elif message.text == "inline":
        markup = types.InlineKeyboardMarkup()
        btn1 = types.InlineKeyboardButton(text='Наш сайт', url='https://www.youtube.com/watch?v=xFoUNDRVBYM')
        btn2 = types.InlineKeyboardButton(text='Сработает?', callback_data="price_1")
        markup.add(btn1, btn2)
        await bot.send_message(message.chat.id, "Нажми на кнопку и перейди на наш сайт.", reply_markup=markup)
    elif message.text == " Профиль":
        await bot.send_message(message.chat.id, f'Имя: {message.from_user.first_name} \nID: {message.from_user.id} \nБаланс: ')
    elif message.text == "Приобрести голду":
        message = await bot.send_message(message.chat.id, "Введите сумму в рублях: ")
        await dp.register_next_step_handler(message, start_2)

# Обработка callback-запросов
@dp.callback_query_handler(lambda call: True)
async def callback_handler(call: types.CallbackQuery):
    if call.message:
        if call.data == 'price_1':
            await bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.id, text='Сработало!')

async def on_startup(dp):
    await bot.send_message(chat_id='YOUR_CHAT_ID', text='Бот запущен')

if __name__ == '__main__':
    executor.start_polling(dp, on_startup=on_startup)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы