How to mention user in slack.client

Posting an updated answer as this method no longer works since Slack updated their API. Now you have to discover the user’s ID using users.list, or just looking it up in the Slack app on their profile.

Then for a given userID, you mention them by setting the text as follows: <@userID>. The link_names argument is now irrelevant. So this would be the code to use now:

message = sc.api_call(
  'chat.postMessage',
  channel="#channelname",
  text="<@userID> This is a test."
  )

HOWEVER, if you want to mention a usergroup, then the old method still applies – just @mention them and in that case do set link_names to true.

Leave a Comment