"memoryDataStore is not a constructor"节点js错误
"memoryDataStore is not a constructor" error in node js
我开始使用 node.js 进行松弛开发。
按照教程,我收到一条错误消息。我尝试了几个来源,但我仍然无法发现我的错误
我只是想打印机器人
和频道名称
安装的node版本是10
但是示例基于版本 5
这可能是错误的来源吗?
'use strict';
const RtmClient = require('@slack/client').RtmClient;
const MemoryDataStore = require('@slack/client').MemoryDataStore;
const RTM_EVENTS = require('@slack/client').RTM_EVENTS;
const CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS;
const token = 'myTokenGoesHere';
let slack = new RtmClient(token, {
logLevel: 'debug',
dataStore: new MemoryDataStore(),
autoReconnect: true,
autoMark: true});
slack.on(CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, () => {
// Get the user's name
let user = slack.dataStore.getUserById(slack.activeUserId);
// Get the team's name
let team = slack.dataStore.getTeamById(slack.activeTeamId);
// Log the slack team name and the bot's name, using ES6's
// template
// string syntax
console.log(`Connected to ${team.name} as ${user.name}`);
});
// Start the login process
slack.start();
我收到此错误消息
> TypeError: MemoryDataStore is not a constructor
> at Object.<anonymous> (C:\Users\ToughBook\appdir\index.js:33:16)
> at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:282:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
如果您真的想按照 Paul 书中的教程进行操作,请使用 slack 客户端的版本 2。
此外,请访问 https://termitedev.slack.com/apps/new/A0F7YS25R-bots 以获取 API 令牌,但请确保您已经拥有一个 slack workspace。
"dependencies": {
"@slack/client": "^2.1.0"
}
我开始使用 node.js 进行松弛开发。 按照教程,我收到一条错误消息。我尝试了几个来源,但我仍然无法发现我的错误
我只是想打印机器人 和频道名称
安装的node版本是10 但是示例基于版本 5
这可能是错误的来源吗?
'use strict';
const RtmClient = require('@slack/client').RtmClient;
const MemoryDataStore = require('@slack/client').MemoryDataStore;
const RTM_EVENTS = require('@slack/client').RTM_EVENTS;
const CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS;
const token = 'myTokenGoesHere';
let slack = new RtmClient(token, {
logLevel: 'debug',
dataStore: new MemoryDataStore(),
autoReconnect: true,
autoMark: true});
slack.on(CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, () => {
// Get the user's name
let user = slack.dataStore.getUserById(slack.activeUserId);
// Get the team's name
let team = slack.dataStore.getTeamById(slack.activeTeamId);
// Log the slack team name and the bot's name, using ES6's
// template
// string syntax
console.log(`Connected to ${team.name} as ${user.name}`);
});
// Start the login process
slack.start();
我收到此错误消息
> TypeError: MemoryDataStore is not a constructor
> at Object.<anonymous> (C:\Users\ToughBook\appdir\index.js:33:16)
> at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:282:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
如果您真的想按照 Paul 书中的教程进行操作,请使用 slack 客户端的版本 2。 此外,请访问 https://termitedev.slack.com/apps/new/A0F7YS25R-bots 以获取 API 令牌,但请确保您已经拥有一个 slack workspace。
"dependencies": {
"@slack/client": "^2.1.0"
}