@app.on_message(gen('spam', allow=['sudo']))
async def spam(_, m: Message):
    replied = m.reply_to_message
    reply_to_id = (replied.message_id if replied else '')
    if ((not replied) and (len(m.command) > 1)):
        (await m.delete())
        times = m.command[1]
        to_spam = ' '.join(m.command[2:])
        if (m.chat.type in ['supergroup', 'group']):
            for _ in range(int(times)):
                (await app.send_message(m.chat.id, to_spam, reply_to_message_id=reply_to_id))
                (await asyncio.sleep(0.2))
        elif (m.chat.type == 'private'):
            (await m.delete())
            for _ in range(int(times)):
                (await app.send_message(m.chat.id, to_spam))
                (await asyncio.sleep(0.2))
    elif (replied and (len(m.command) > 1)):
        (await m.delete())
        times = m.command[1]
        print(f'{times} messages will be sent')
        cont = m.reply_to_message.message_id
        if (m.chat.type in ['supergroup', 'group', 'private']):
            for x in range(int(times)):
                (await app.copy_message(m.chat.id, m.chat.id, m.reply_to_message.message_id))
        else:
            return
@app.on_message(gen('spam', allow=['sudo']))
async def spam(_, m: Message):
    replied = m.reply_to_message
    reply_to_id = (replied.message_id if replied else )
    if ((not replied) and (len(m.command) > 1)):
        (await m.delete())
        times = m.command[1]
        to_spam = ' '.join(m.command[2:])
        if (m.chat.type in ['supergroup', 'group']):
            for _ in range(int(times)):
                (await app.send_message(m.chat.id, to_spam, reply_to_message_id=reply_to_id))
                (await asyncio.sleep(0.2))
        elif (m.chat.type == 'private'):
            (await m.delete())
            for _ in range(int(times)):
                (await app.send_message(m.chat.id, to_spam))
                (await asyncio.sleep(0.2))
    elif (replied and (len(m.command) > 1)):
        (await m.delete())
        times = m.command[1]
        print(f'{times} messages will be sent')
        cont = m.reply_to_message.message_id
        if (m.chat.type in ['supergroup', 'group', 'private']):
            for x in range(int(times)):
                (await app.copy_message(m.chat.id, m.chat.id, m.reply_to_message.message_id))
        else:
            return