Skip to content

Instantly share code, notes, and snippets.

@rummanwaqar
Created September 18, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rummanwaqar/03bba7e2eaa92775938438a4fc64cb2e to your computer and use it in GitHub Desktop.
Save rummanwaqar/03bba7e2eaa92775938438a4fc64cb2e to your computer and use it in GitHub Desktop.
Retrieves emails for all users in a slack channel
'''
pip install slackclient
You can generate or find your personal Slack token here: https://api.slack.com/custom-integrations/legacy-tokens
'''
import sys
from slackclient import SlackClient
if len(sys.argv) != 3:
print('Usage: python slack_emails.py token channel')
exit(1)
auth_token = sys.argv[1]
specific_channel = sys.argv[2]
sc = SlackClient(auth_token)
members = None
for channel in sc.api_call('channels.list')['channels']:
if channel['name'] == specific_channel:
members = channel['members']
if not members:
print('No members for channel {}'.format(specific_channel))
exit(1)
else:
for member in members:
print(sc.api_call('users.info', user=member)['user']['profile']['email'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment