Код на аиограме издает ошибку
first_user = call_sp[0][0]
IndexError: list index out of range
Код рассылки:
@dp.message_handler(lambda message: message.text == 'Розсилка на random user')
async def rozsulka(message):
user_id = str(message.from_user.id)
if user_id in config.admin:
await message.reply('Очікую повідомлення...')
await Mailing.Text.set()
else:
mention = "[" + str(message.from_user.first_name) + \
"](tg://user?id=" + str(message.from_user.id) + ")"
await bot.send_message(config.error, f"{mention} хоче зробити розсилку", parse_mode="Markdown")
@dp.message_handler(state=Mailing.Text, content_types=types.ContentType.ANY)
async def rozsulka_f(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['Text'] = message.text
await state.update_data(Text=(message.text))
await message.reply('Введіть кількість користувачів:')
await Mailing.next()
@dp.message_handler(lambda message: message.text.isdigit(), state=Mailing.Count_User, content_types=types.ContentType.ANY)
async def rozsulka_full(message: types.Message, state: FSMContext):
result = ""
with sq.connect("clients.db") as con:
cur = con.cursor()
result = cur.execute('SELECT `id` FROM `users`').fetchall()
call_sp = cur.fetchall()
error = 0
good = 0
async with state.proxy() as data:
data['Count_User'] = message.text
msg = data['Text']
count = int(data['Count_User'])
for user in result:
first_user = call_sp[0][0]
del [call_sp[0]]
user = user[0]
if(count > good):
if(random.choice([True, False])):
try:
await bot.send_message(user, str(msg))
good += 1
except:
error += 1
await bot.send_message(config.error, f"Розсилка: \nУспішно: {good} \nНе пройшло: {error}")
await state.finish()
Айдишники есть в базе