I make my own echo bot that sends out a message to all bot users, kind of like an anonymous chat. (echo-to-all) I’m trying to add replies to it, and when i reply to my own message it’s fine, but if i try to reply to someone else’s message, i get an error: Message to be replied not found. Also, for some reason this reply is only visible to me. aiogram 2.25.1. MAIN ECHO FUNCTION:
@dp.message_handler(content_types=types.ContentType.ANY)
async def echo(msg: types.Message):
global is_bot_closed
current_time = time.time()
if is_bot_closed and msg.from_user.id != ADMIN_ID:
await msg.reply("Сейчас писать могут только админы.")
return
if msg.from_user.id in last_message_time:
time_since_last_message = current_time - last_message_time[msg.from_user.id]
time_remaining = MESSAGE_DELAY - time_since_last_message
if time_remaining > 0:
await msg.reply(f"Подождите еще {round(time_remaining, 1)} секунд.")
return
last_message_time[msg.from_user.id] = current_time
if db.is_user_banned(msg.from_user.id):
await msg.reply('Вы забанены и не можете использовать этого бота. Обратитесь к @cry4he1p')
return
if not db.sas(msg.from_user.id):
await msg.reply('Сначала введите команду /start, чтобы начать взаимодействие с ботом.')
return
if msg.reply_to_message is not None:
original_message_id = msg.reply_to_message.message_id
else:
original_message_id = None
user_id = msg.from_user.id
is_anon = db.get_anon_mode(user_id)
show_link = db.get_show_link(user_id)
x = db.get_ids()
users = len(x)
keyboard = create_keyboard(user_id, msg.from_user.first_name, anon=is_anon, show_link=show_link)
reply_message = await msg.reply(f'Отправляю ваше сообщение {users} пользователям. (а может и нет..)')
for i in x:
try:
zc = db.chek(i[0])
if zc[0][0] == 1:
try:
if msg.content_type == types.ContentType.TEXT:
await bot.send_message(chat_id=i[0], text=msg.text, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.PHOTO:
await bot.send_photo(chat_id=i[0], photo=msg.photo[-1].file_id, caption=msg.caption, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.AUDIO:
await bot.send_audio(chat_id=i[0], audio=msg.audio.file_id, caption=msg.caption, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.DOCUMENT:
await bot.send_document(chat_id=i[0], document=msg.document.file_id, caption=msg.caption, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.VIDEO:
await bot.send_video(chat_id=i[0], video=msg.video.file_id, caption=msg.caption, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.ANIMATION:
await bot.send_animation(chat_id=i[0], animation=msg.animation.file_id, caption=msg.caption, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.VOICE:
await bot.send_voice(chat_id=i[0], voice=msg.voice.file_id, caption=msg.caption, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.VIDEO_NOTE:
await bot.send_video_note(chat_id=i[0], video_note=msg.video_note.file_id, reply_markup=keyboard, reply_to_message_id=original_message_id)
elif msg.content_type == types.ContentType.STICKER:
await bot.send_sticker(chat_id=i[0], sticker=msg.sticker.file_id, reply_markup=keyboard, reply_to_message_id=original_message_id)
except (BotBlocked, ChatNotFound, UserDeactivated):
logging.error(f"User {i[0]} has blocked the bot, the chat does not exist, or the user is deactivated. Skipping.")
except aiogram.utils.exceptions.MessageToReplyNotFound:
logging.error(f'Message to reply to {original_message_id} not found for user {i[0]}. Skipping reply.')
except Exception as e:
logging.error(f'Error sending message to {i[0]}: {e}')
if not db.sas(msg.from_user.id):
await db.add(msg.from_user.id, msg.from_user.username)
except Exception as e:
logging.error(f'Error processing user {i[0]}: {e}')
await asyncio.sleep(REPLY_MESSAGE_TIMEOUT)
try:
await bot.delete_message(chat_id=msg.chat.id, message_id=reply_message.message_id)
except aiogram.utils.exceptions.MessageToDeleteNotFound:
logging.error(f'Message to delete {reply_message.message_id} not found.')
I haven’t tried anything because I don’t know what
1