Столкнулся с проблемой, что бот не отвечает на мои команды.Пробовал перечитать код на наличие синтаксических ошибок, перепроверял, работают ли команды без кнопок, но так и не сообразил в чём тут дело. Прошу помочь, вот код:
create_bot.py
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from config import TOKEN
import json
from aiogram.contrib.fsm_storage.memory import MemoryStorage
storage=MemoryStorage()
bot = Bot(token=TOKEN)
dp = Dispatcher(bot, storage=storage)
main.py
from aiogram.utils import executor
from create_bot import dp
from data_base import sqlite_db
async def on_startup(_):
print('Бот вышел в онлайн')
sqlite_db.sql_start()
from handlers import client, admin
client.register_handlers_client(dp)
admin.register_handlers_admin(dp)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)
client.py
from aiogram import types, Dispatcher
from create_bot import dp, bot
from keyboards import kb_client
#from aiogram.types import ReplyKeyboardRemove
from data_base import sqlite_db
#@dp.message_handler(commands=['start', 'help'])
async def command_start(message : types.Message):
try:
await bot.send_message(message.from_user.id, ' - Магазин вкусного пара и хорошего настроения ', reply_markup=kb_client)
await message.delete()
except:
await message.reply('Общение с ботом через ЛС, напишите ему:\n@vapoxabot')
#@dp.message_handler(commands=['Расположение'])
async def vape_place_command(message : types.Message):
await bot.send_message(message.from_user.id, 'Город Сумы')
#@dp.message_handler(commands=['Товар'])
async def vape_staff_command(message : types.Message):
await sqlite_db.sql_read(message)
#@dp.message_handler(commands=['Поддержка'])
async def vape_admin_command(message : types.Message):
await bot.send_message(message.from_user.id, '@vapoxa_admin')
def register_handlers_client(dp : Dispatcher):
dp.register_message_handler(command_start, commands=['start', 'help'])
dp.register_message_handler(vape_place_command, commands=['Расположение'])
dp.register_message_handler(vape_staff_command, commands=['Товар'])
dp.register_message_handler(vape_admin_command, commands=['Поддержка'])
client_kb.py
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove
b1 = KeyboardButton('Расположение')
b2 = KeyboardButton('Товар')
b3 = KeyboardButton('Поддержка')
kb_client = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=None)
kb_client.add(b1).add(b2).add(b3)
#.add()
#.insert()
#.row()
admin.py
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram import types, Dispatcher
from create_bot import bot, dp
from aiogram.dispatcher.filters import Text
from data_base import sqlite_db
from keyboards import admin_kb
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
ID = None
class FSMAdmin(StatesGroup):
photo = State()
name = State()
description = State()
price = State()
#Получаем ID текущего модератора
#@dp.message_handler(commands=['moderator'], is_chat_admin=True)
async def make_changes_command(message: types.Message):
global ID
ID = message.from_user.id
await bot.send_message(message.from_user.id, 'Выберите команду', reply_markup=admin_kb.button_case_admin)
await message.delete()
#Начало диалога загрузки нового пункта меню
# @dp.message_handler(commands='Загрузить', state=None)
async def cm_start(message : types.Message):
if message.from_user.id == ID:
await FSMAdmin.photo.set()
await message.reply('Загрузите фото:')
# @dp.message_handler(state='*', commands='Отмена')
# @dp.message_handler(Text(equals='отмена', ignore_case=True), state='*')
async def cancel_handler(message: types.Message, state: FSMContext):
if message.from_user.id == ID:
current_state = await state.get_state()
if current_state is None:
return
await state.finish()
await message.reply('Отменено ✅')
#Ловим первый ответ и пишем в словарь
# @dp.message_handler(content_types=['photo'], state=FSMAdmin.photo)
async def load_photo(message: types.Message, state: FSMContext):
if message.from_user.id == ID:
async with state.proxy() as data:
data['photo'] = message.photo[0].file_id
await FSMAdmin.next()
await message.reply('Введите название продукта:')
#Ловим второй ответ
# @dp.message_handler(state=FSMAdmin.name)
async def load_name(message: types.Message, state: FSMContext):
if message.from_user.id == ID:
async with state.proxy() as data:
data['name'] = message.text
await FSMAdmin.next()
await message.reply('Введите описание товара:')
#Ловим третий ответ
#@dp.message_handler(state=FSMAdmin.description)
async def load_description(message: types.Message, state: FSMContext):
if message.from_user.id == ID:
async with state.proxy() as data:
data['desription'] = message.text
await FSMAdmin.next()
await message.reply('Укажите цену товара:')
#Ловим последний ответ и используем полученные данные
# @dp.message_handler(state=FSMAdmin.price)
async def load_price(message: types.Message, state: FSMContext):
if message.from_user.id == ID:
async with state.proxy() as data:
data['price'] = float(message.text)
await sqlite_db.sql_add_command(state)
await state.finish()
@dp.callback_query_handler(lambda x: x.data and x.data.startswitch('del '))
async def del_callback_run(callback_query: types.CallbackQuery):
await sqlite_db.sql_delete_command(callback_query.data.replace('del ', ''))
await callback_query.answer(text=f'{callback_query.data.replace("del ", "")} удалена.', show_alert=True)
#@dp.message_handler(commands='Удалить')
async def delete_item(message: types.Message):
if message.from_user.id == ID:
read = await sqlite_db.sql_read2()
for ret in read:
await bot.send_photo(message.from_user.id, ret[0], f'{ret[1]}\nОписание: {ret[2]}\nЦена {ret[-1]}')
await bot.send_message(message.from_user.id, text='^^^', reply_markup=InlineKeyboardMarkup().\
add(InlineKeyboardButton(f'Удалить {ret[1]}', callback_data=f'del {ret[1]}')))
#Регистрируем хендлеры
def register_handlers_admin(dp : Dispatcher):
dp.register_message_handler(cm_start, commands=['Загрузить'], state=None)
dp.register_message_handler(cancel_handler, state='*', commands='отмена')
dp.register_message_handler(cancel_handler, Text(equals='отмена', ignore_case=True), state='*')
dp.register_message_handler(load_photo, content_types=['photo'], state=FSMAdmin.photo)
dp.register_message_handler(load_name, state=FSMAdmin.name)
dp.register_message_handler(load_description, state=FSMAdmin.description)
dp.register_message_handler(load_price, state=FSMAdmin.price)
#dp.register_message_handler(make_changes_command, commands=['moderator'], is_chat_admin=True)
dp.register_message_handler(delete_item, commands=['Удалить'])
admin_kb.py
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
#Кнопки клавиатуры админа
button_load = KeyboardButton('Загрузить')
button_delete = KeyboardButton('Удалить')
button_case_admin = ReplyKeyboardMarkup(resize_keyboard=True).add(button_load)\
.add(button_delete)
__init__.py "хендлеры"
from keyboards.client_kb import kb_client
__init__.py "клавиатуры"
from handlers import client
from handlers import admin