What was the function of the guild in the middle ages?

to look after the rights of the members of that guild