There's no secret to this. It's very much common sense. The same way you keep your friends, you keep your readers. However, if you're someone who claims not to have any friends, this blog will provide some insights that you can consider trying.
Patreons to credit: -This could be you. Join now.-
Firstly, I'd ask you to identify the kind of writer before reading the rest of my blog. If you're a writer who identifies your main focus of writing any book with money in mind, walk away. This is not a blog for you. However, if your main purpose of writing a book is to share with others all the good that you can offer through your works, continue on.
#1: Talk to Them
How else would they know that you exist? It's common sense here. If you want your readers to know you, you need to introduce yourself. No, author notes do not count. I'm talking about a sincere one-to-one interaction and not a public announcement.
You have no idea how many readers' day I made with just a simple "Thanks" comment. If they bothered to go that extra mile to leave you some form of a comment in a non-negative manner, I believe they deserve cookies in the form of an author acknowledgement for that effort.
Communicating is the first step to making that random reader your random reader.
#2: Include Them
So you got them to finally notice you. Of the hundreds of books and authors they read and follow, how many do they really get a chance to know up and personal? I don't think many authors give their readers enough credits or space to express themselves clearly. Society is often judgemental. They don't need that from you. Instead, welcome them warmly to say what they want to say and just listen.
Include them in a space of like-minded readers and encourage discussion without shutting anyone out if they are not being toxic. Refrain from correcting them as much as possible and exercise empathy. Like this, you're one step closer to moving from "that random author" to "the author of xxx book".
#3: Tease Them
In any kind of relationship when both parties are fond of each other, they want attention from the person they admire. Boys tug at the pigtails of the girls they like and girls bother the boys they like with dumb problems. It's similar between a reader and a writer.
Once you pass that barrier of "that random writer" into "writer-san", you want them to start dropping that honorific. A good way to do so is to tease them. Use memes, jokes, target their previous stories and make fun of them in a non-hurtful manner in the name of good-natured comedy. Flex your intellectual humour and vibe with them. In no time, you'll soon find yourself coaxing them to join your discord server and following your Instagram without effort.
Bonus points to them if they ask you for links first before you give it. Extra bonus points if they found the links without even asking for it. That's how you know if they are going to be your long-ride reader BFF.
#4: Spoil Them
No, I'm not talking about book spoilers. That's for every individual writer to decide. I personally don't like giving spoilers like additional content rewards for joining my exclusive club. If anything, it's an idea I hate. You don't need to sign up for anything you don't want to unless it's on Patreon. I'd give spoilers in the comment section if a reader asked about it, they don't have to come to discord or Instagram.
When I say spoil them, I'm talking about making your reader BFF feel all the love they could possibly get from across the screen the same way a long-distance lover would spoil you. You might not be sugar daddy/mommy material but you can still spoil them by doing little things such as giving them a shoutout in your author notes or borrowing their names in your story as a random NPC.
At this point, you and your reader are practically married or if you're not, you are both in a very serious and committed relationship.
#5: Harass Them
Writers are sinful creatures. At some point in time, you've collected yourself a harem of loyal readers in your discord server and on your Instagram. Your popularity skyrockets with twenty loyal subjects at your beck and call. You feel like the most powerful king of a nation you founded from nothing and are trippy on the new power high.
All that effort from sharing something you loved has paid off and now you can share even more with your plethora of supporters. The people in your harem understand now that they are not truly special and have to work hard for your undivided attention. They subscribe to everything you own and scramble to get the first comment the moment a chapter drops. Yet, it somehow isn't enough for them.
Why not help them out by spam pinging them on your server whenever you can? Everything from "I'm sorry the chapter is going to be 5 minutes late today!" to "Check out the sexy pineapple pizza I made today!" is pingable.
You have the power now and it's too late for them to leave. Why not abuse it? Harass them to your heart's content and watch them profess their undying love for you. MUHAHA!
While not all those steps work for everyone, I believe that the majority of readers who can put up with my nonsense as an author will definitely stay for the long haul. It takes the right people in the right place to create the right community.