Ad

Channel_not_found Error While Sending A Message To Myself

- 1 answer

I'm using python3.6 and trying to send message to myself to start interacting in slack.

I've installed pip install slackclient and am using slackclient v2.2.1

channel ID is extracted from slack link of my account https://XXXXX.slack.com/messages/XXXXXXXXX

I would like to see Hi message in my slack account. any suggestions.


client = slack.WebClient("BOT_USER_TOKEN", timeout=30)
client.chat_postMessage(
    channel='CHANNEL_ID',
    text='Hi!')```


Ad

Answer

The bot user token is linked to a bot user that is created with your app. If you use the bot token you will only have access to channels that this bot user is a member of.

So to make your script work you need to do one of the following:

  • Use the access token instead of the bot token (that one is linked to the user that installed the Slack app)
  • Invite the bot user to the channel you are trying to send a message to

As you want to start with basics, I would recommend to use public channels first, which will always work.

Direct messages are a little bit more complicated. To send a direct message to a user (e.g. from your bot user to yourself) you need to first open a direct message channel with conversations.open, which will give you a new channel ID. And then use that channel ID for sending a message.

Ad
source: stackoverflow.com
Ad