After falling out with a Portuguese man, John Kerr posted a message on Facebook suggesting he return to his home country.
The 46-year-old, of Scott Crescent, admitted posting a message on the social media website which contained abusive and racially offensive remarks on February 16.
Prosecutor Tessa Bradley told Selkirk Sheriff Court that the offence was committed against a “background of ill-feeling” between the accused and the complainer, who has been in Scotland for some six years.
Kerr posted a message on someone else’s page suggesting “send all the f**kers back to where they came from”.
When the complainer heard about the message, he reported matters to police.
Defence solicitor Mark Harrower said Kerr had known the man for some time, but there had been “fallout”.
Mr Harrower added: “He took it upon himself to join in a conversation on Facebook, and says he very much regrets making the comment.”
Kerr was sentenced to a Community Payback Order with 80 hours of unpaid work.