The immune system does a number of things to provide an immediate nonspecific immune response. There are skin cells and mucus membranes that are able to prevent many pathogens from entering the body.
Skin has a low pH, fatty acids, and salts found on it that serve as chemical barriers to prevent infectious invaders from entering the body. The first thing the immune system does is to use mucus to sweep out the pathogens before even knowing what the bacterium is but there is a completely different process for when invaders
Inflammation
When skin is pierced and something punctures a body cell, it releases chemicals such as histamines that tell white blood cells, natural killer cells, and Phagocytes such as macrophages to surround and destroy foreign microbes. Then, fluid moves into the area which explain the swelling of the inflamed area, the local blood vessels are now leaky and blood vessels are dilated in order for a greater chance for infection fighting cells to enter the area. Phagocytes then consume bacteria and cell debris, healing the tissue. Phagocytes consume bacteria by finding the carbohydrates found in the bacteria, surrounding them and using lysosomes to kill and digest the bacteria. The kinds of chemicals that are released during tissue injury are histamine, prostaglandins, kinines, complement, and cytokines. These mediators work to increase blood flow by increasing the metabolic rate which explain the redness and heat. Then, they make local capillaries permeable which swell and make the area very sensitive to pressure. This brings oxygen and nutrients into and clotting proteins into the area. Also, mediators such as histamine help in phagocyte mobilization.
Here is an interesting picture to see what happens. Summary of what I explained.
T and B cells in infections
T and B cells are very different.
There are two types of T and B cells, there is a t helper cell that activate B cells and receive information from macrophages and cytoxic T cells that target and destroy infected cells. B cells are divided between memory cells that remember the shape of antigens and antibody b cells that create antibodies to attach to antigens that stop them in their tracks and tell killer cells to get rid of them. Memory B cells recognize these antigens by their shape and when they deal with them, they remember the shape of the antigens and are more prepared the second time the antigens appear again. Antibody B-cells are present to create Y shaped proteins called antibodies that stick to foreign invaders and that alert the body to the invader's presence. Basically, this is a watch guard that is yelling "HEY LOOK THERE IS A BAD GUY HERE KILL HIM". Phagocytes, natural killer cells, and cytoxic T cells then kill and destroy the intruders or infected covered with antibodies. T cells are activated when a phagocyte eats a foreign substance and takes it to the spleen to figure out what it is. The T cells kill the invader and the b cells create antigens that are able to bind to the invader. When it happens a second time, this is able to be done much faster because the b cells remember the shape of the invader now. This is why we have antibiotics and vaccinations so B cells can get the shape of the disease without actually getting the disease and be able to react to the infection much faster than it usually would
Notice this how a helper T cell receives information and activates other cells. .
The entire process. Notice how the Helper T cell is the first thing that receives the antigen and stimulates the B cells and memory T cells and Memory B cells.
T and B cells against themselves?
T and B cells can distinguish invader from self because the ones that distinguish molecules in our body have been destroyed while in the womb. The rest are memory cells that are trained to identify new invaders that enter the body rather than cells that already exist in the body.
T and B cells work together to remember invaders through shape and attack them when they recognize them.
Every cell also has a major histocompatibility complex(MBC) that is able to tell T and B cells if they are targeting themselves or not. This is why we cannot simply just accept someone else's liver because their liver's MBCs are different from ours and will be rejected by our body and attacked because our body will think the liver is a foreign invader.
Notice the MHC present that tells T and B cells it is self.