Assuming this is for developers:
Close slack and email client for a given amount of time. Say keep it closed for 1 hour, then pop up to check it.
If you need to be urgently contacted sometimes, give such people your phone number, or another way to contact that is more intrusive. e.g. WhatsApp.
When using Slack or email, completely deal with one message (even if just creating a ticket to deal with it later) before reading the next.