必须代表bot发送2+图片,并且帖子下的文字也必须存在。但默认情况下,机器人会发送第一张图片,而忽略其余的。
主页
/
user-516117
Corn's questions
常规消息和表情可以通过 删除delete_message
,但贴纸和 GIF 不属于此范围。如何实际删除这些贴纸和 GIF?
艾奥加姆图书馆。我有一个列表,我需要使用此列表中的名称创建 KeyboardButton 类型的按钮。那些。假设列表是 [('print',), ('enter',), ('delete',), ('add',), ('home',)] (这个列表是从数据库查询中获得的)。并且您需要创建 5 个具有适当名称的 KeyboardButton 类型(粗略地说是键盘)的按钮(即列表中的元素数)。
async def choice_cat(message):
CATs = cur.execute(f'SELECT name FROM cathlete WHERE id = "{message.from_user.id}"').fetchall()
for fds in range(len(CATs)):
astt = ReplyKeyboardMarkup(resize_keyboard=True).add(KeyboardButton(f"CATs[{fds}]"))
不应该考虑以“为”开头的东西,我的病态幻想!我试图随机找到一种方法,但无济于事(
当您在聊天中键入单词:/changes 时,状态机应该启动。但是什么也没有发生!代码分为模块,没有乱七八糟,代码运行无误,但状态机不启动(
from aiogram import types, Dispatcher
from create_bot import dp, bot
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from data_base import botbd
from aiogram.types import ReplyKeyboardRemove, \
ReplyKeyboardMarkup, KeyboardButton, \
InlineKeyboardMarkup, InlineKeyboardButton
#появляется после ввода /start
button_menu = KeyboardButton("Меню")
greet_kb = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True).add(button_menu)
#появляется после ввода слова Меню
button_wr = KeyboardButton("/изменения")
button_stats = KeyboardButton("stats")
button_other = KeyboardButton("other")
button_info = KeyboardButton("info")
greet_menu = ReplyKeyboardMarkup(resize_keyboard=True).add(button_wr, button_stats, button_other, button_info)
#при вводе /start
#@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
await message.answer("Привет, для продолжения перейдите в меню!", reply_markup=greet_kb)
#@dp.message_handler()
async def menu_command(message : types.Message):
if message.text == 'меню' or message.text == 'Меню':
await message.answer("Сделайте свой выбор!", reply_markup=greet_menu)
################################################################
class FSMAdmin(StatesGroup):
winers = State()
losers = State()
#тут машина состояния должна начать работать, после выбора на клавиатуре кнопки /изменения
#@dp.message_handler(commands='изменения', state=None)
async def cm_start(message : types.Message):
await FSMAdmin.winers.set()
await message.reply('Введите количество побед:')
#@dp.message_handler(state=FSMAdmin.winers)
async def load_win(message : types.Message, state: FSMContext):
async with state.proxy() as data:
data['winers'] = message.text
await FSMAdmin.next()
await message.reply('Введите количество поражений:')
#@dp.message_handler(state=FSMAdmin.losers)
async def load_lose(message : types.Message, state: FSMContext):
async with state.proxy() as data:
data['losers'] = message.text
await botbd.sql_add_command(state)
await state.finish()
def register_handlers_client(dp : Dispatcher):
dp.register_message_handler(process_start_command, commands=['start'])
dp.register_message_handler(menu_command)
dp.register_message_handler(cm_start, commands='изменения', state=None)
dp.register_message_handler(load_win, state=FSMAdmin.winers)
dp.register_message_handler(load_lose, state=FSMAdmin.losers)
这是在运行的主文件中:
from aiogram.utils import executor
from create_bot import dp
from handlers import client, other
from data_base import botbd
client.register_handlers_client(dp)
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)
它在 dp 文件中:
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from config import TOKEN
from aiogram.contrib.fsm_storage.memory import MemoryStorage
storage = MemoryStorage()
bot = Bot(token=TOKEN)
dp = Dispatcher(bot, storage=storage)