Skip to content

Instantly share code, notes, and snippets.

@haimingzhao
Last active September 16, 2021 15:18
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 haimingzhao/9016b34364722bd1f0124d6cb2835ea0 to your computer and use it in GitHub Desktop.
Save haimingzhao/9016b34364722bd1f0124d6cb2835ea0 to your computer and use it in GitHub Desktop.
Get more than 100 usernames from a slack channel
import os
import requests
SLACK_API_TOKEN='' # Your token here
FROM_CHANNEL_ID='' # Get the id from the bottom of the channel description
NEW_CHANNEL_ID=''
LIMIT=200 # default limit was 100 need to change based on size
members = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s&limit=%s' % (SLACK_API_TOKEN, FROM_CHANNEL_ID, LIMIT)).json()['members']
existing_members = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s&limit=%s' % (SLACK_API_TOKEN, NEW_CHANNEL_ID, LIMIT)).json()['members']
for id in members:
if id not in existing_members:
# print(id)
user = requests.get('https://slack.com/api/users.info?token=%s&user=%s' % (SLACK_API_TOKEN, id)).json()
if user['ok']:
print('@' + user['user']['name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment