Search code examples
node.jsslackslack-api

Slack bot ALWAYS gives missing_scope error


I'm new to Slack bots so I went through their documentation and followed some tutorials on the internet but nothing seems to help. I'm trying to add a simple bot to a workspace I've just created, all I want is to make the bot post a message once it starts. Here is my code:

const SlackBot = require('slackbots');

const botToken = 'xoxp-XXXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXX'

const bots = async () => {

    const bot = await new SlackBot({
        token: botToken,
        name: 'orderbot'
    });

    console.log('adding event listener...');

    await bot.on('start', () => {
        console.log('posting message...');
        bot.postMessage('general', 'Feeling hungry?');
    });
};

bots();

And in the OAuth & Permissions page, I've added ALL permissions to the token's scopes. Running the bot, here is my output:

adding event listener...
/home/mohammed/OrderBot/node_modules/vow/lib/vow.js:105
            throw e;
            ^

Error: missing_scope
    at /home/mohammed/OrderBot/node_modules/slackbots/index.js:46:33

So apparently, the error is coming from the .on listener which is quite confusing and I can't understand why this is happening. What exactly am I missing?


Solution

  • It seems like the module slackbots which I was using is not working properly (at least for me). I solved this issue by using @slack/web-api instead.