Yes, the way you answered the question is correct. You provided a polite response to the question "¿Quieres comer pastel de cebollas conmigo?" which means "Do you want to eat onion cake with me?" by saying "Lo siento pero no, no me gusta pastel de cebollas," which means "Sorry, but I don't like onion cake." You also concluded your response by saying "Thank you" which is a polite gesture. Well done!