Melania Trump Called for Good Behavior on Social Media. The President Unleashed More Attacks on Twitter.

ROCKVILLE, Md. — Under the banner of her “Be Best” campaign, Melania Trump, the first lady, told a group of cyberbullying prevention experts on Monday that social media “can be destructive and harmful when used incorrectly.”

Just after she spoke, President Trump unleashed a barrage of tweets in which he called the former director of the C.I.A. a “hack” and mocked the effectiveness of the Justice Department, among other digital insults on a day of dissonant messaging from the Trump White House.

Mrs. Trump, whose policy director left the White House a few weeks ago, has kept a light public schedule in promoting her child-focused campaign since she launched it in May. Her visit to the Federal Partners in Bullying Prevention session, held at the Health Resources and Services Administration in a Washington suburb, was one of the more visible efforts that Mrs. Trump has made on behalf of the campaign.

“In today’s global society, social media is an inevitable part of our children’s daily lives,” Mrs. Trump said, reading from prepared remarks. “It can be used in many positive ways, but can also be destructive and harmful when used incorrectly.”

The first lady has stuck with cyberbullying prevention as a signature issue despite Mr. Trump’s combative posture on Twitter — he has attacked at least 487 people, companies or institutions since declaring his candidacy for the presidency. His targets have ranged from the department store Macy’s to Robert S. Mueller III, the special counsel investigating the Trump campaign’s ties to Russia.

Shortly before Mrs. Trump departed the White House for the meeting in Maryland, Mr. Trump attacked the “disgraced and discredited” Mr. Mueller and “his whole group of Angry Democrat Thugs” for extensively interviewing Donald F. McGahn II, the White House counsel.

“They are enjoying ruining people’s lives and REFUSE to look at the real corruption on the Democrat side — the lies, the firings, the deleted emails and soooo much more,” Mr. Trump wrote in a pair of tweets disparaging the investigation. “Mueller’s Angry Dems are looking to impact the election. They are a National Disgrace!”

Over the weekend, the president sent several angry tweets, spurred by a report by The New York Times that revealed Mr. McGahn’s extensive cooperation with the special counsel’s office. And days ago, Mr. Trump called a former White House official, Omarosa Manigault Newman, “that dog” and a “crazed, crying lowlife” on Twitter after she alleged in a publicity campaign for her new book that his mental state had deteriorated.

The president’s tweets were not discussed during the summit the first lady attended. Instead, Lauren Culbertson, who manages public policy for Twitter, touted the platform’s anti-bullying tools as Mrs. Trump sat in the audience.

“We have strong rules against abusive behavior,” Ms. Culbertson said, “One beautiful thing about Twitter is that people come to Twitter to find community and have conversations.”

Another running theme at the cyberbullying summit was the importance of adults understanding how bad behavior on social media could affect children, and how adults can be good digital role models.

“Let’s face it,” Mrs. Trump said during her remarks. “Most children are more aware of the benefits and pitfalls of social media than some adults, but we still need to do all we can to provide them with information and tools for successful and safe online habits.”

Despite her husband’s proclivity to use the platform to target individuals, Mrs. Trump has held firm to her commitment to help end cyberbullying.

As Mrs. Trump listened to the panel, the president sent another tweet. He called John O. Brennan, the former director of the C.I.A. whose security clearance he revoked last week, the “worst C.I.A. director in our country’s history” and a “political hack.”

Mr. Brennan has hit back at the president in recent days, writing in The New York Times that the president was attempting “to scare into silence others who might dare to challenge him.”

Mrs. Trump and her aides have repeatedly acknowledged the conflict between her messages and those of her husband.

“I am well aware that people are skeptical of me discussing this topic,” Mrs. Trump said as she participated in a similar panel in March. “I have been criticized for my commitment to tackling this issue, and I know that will continue. But it will not stop me from doing what I know is right. I am here with one goal: helping children and our next generation.”

On Monday, Stephanie Grisham, the first lady’s communications director, reiterated much of what the first lady said in March — “She is aware of the criticism but it will not deter her from doing what she feels is right,” she wrote in an email — and added that “the President is proud of her commitment to children and encourages her in all that she does.”