The Roseanne Barr scandal took an interesting turn Wednesday. The newly fired television star tweeted a halfhearted apology for a racist tweet from the day before, blaming her poor judgment on her use of the sleeping pill Ambien.

But enough has been said about Roseanne and her comments already.  I'm more interested in discussing how Sanofi, the makers of Ambien, responded to being dragged into this self-inflicted social-media celebrity meltdown:

The best defense is a good offense, right? This tweet is intentionally direct, explicit, funny, engaging, and very, very human.

It reminds the reader that the company isn't some faceless multinational, but made up of people of all races, religions, and nationalities. It uses Roseanne's tweet as an opportunity to position themselves as a company that improves the lives of people around the world.

It only took one tweet for the pharmaceutical giant to distance itself from the scandal--while simultaneously positioning itself positively in the minds of a much larger audience. Barr has over 837,000 followers, while Sanofi has less than 65,000--but in one fell swoop, Sanofi  grabbed the narrative, turning a potential threat into a PR opportunity.

So what should you do when your brand is attacked online? How should you react to being #bashtagged? Here are six pieces of advice I often give to startups:

1. If it starts publicly, it stays public. React accordingly.

Publicly respond to each and every threat, claim, and question. Make sure your side of the story is on the public record. Otherwise, outsiders have only the trolls' frame of reference.

My favorite example is the Fair Trade campaign against Nespresso in 2011. Having a fast-reacting crisis management was key for Nespresso to gain control of the situation--a response so effective that Harvard now uses it as a case study.

2. Be timely.

The internet and social media move like wildfire. The more quickly you start telling your side of the story, the more quickly you can put out the fire. Within minutes is best. If you're waiting hours to respond, you're probably too late. Remember, this is internet time.

3. Plan the work. Work the plan.

Invest time well in advance on how you will react if this should happen to your business.   Ready the plan well before it's necessary, and constantly keep it updated.

Your emergency social-media plan should be like a good fire alarm: always vigilant, hopefully unneeded. When you do have to execute the plan, take confidence in the preparation you have undertaken.

The plan should outline who decides your response, who crafts the response, and who signs off on the response. In some cases, you can create prepared language that can be used as a starting point. Ideally, this emergency response plan should be part of your wider, all-encompassing internal social-media policy.

4. Remember that a great wall is made of many bricks.

Create and manage how you represent yourself over time. Make each individual contribution to the public discourse worth the time, effort, and opportunity you have invested in it. You will be judged by your actions over time, not by simple one-off events.

5. Learn.

Build a culture designed to turn complaints into opportunities to illustrate your brand and all it has to offer. Every complaint offers a wealth of learnings. Turn into them, resolve them transparently, and with gratitude, most will resolve themselves.

6. Accept the things you can't change in life.

You're not going to turn an online troll into your new BFF. You're not even likely to change their mind. All you can do is manage your response.

Put another way, you can't stop a bully from yelling at you. You can--and should--mitigate how that affects your response.

One mistake is all it takes. Brands can damage themselves in a literal internet minute. So, let me be clear: Founders of all sizes need to be prepared. This is a "when" scenario, not an "if" scenario.

Install a social monitoring tool for your venture, so you have an early warning system for social-media swells (the easiest is Google Alerts, which is free to use). Accept that you may get #bashtagged or otherwise attacked online. Prepare for it, so that when it comes, you can act: directly, succinctly, and in a timely manner.

Doing so won't stop the trolls. It will, however, limit the damage they cause.