vitalyavolyn / node-vk-bot

Create and control VK bots easily.
MIT License
34 stars 11 forks source link

Bot is not defined #19

Closed quintendewilde closed 6 years ago

quintendewilde commented 6 years ago

Hi, I'm new at this.

but when I run node in my console and then try to create a bot with my token I get following error.

ReferenceError: Bot is not defined
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:442:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.Interface._line (readline.js:631:8)
vitalyavolyn commented 6 years ago

Hi! Seems like you didn't require the module. Use const { Bot } = require('node-vk-bot') to import it If it shows "Error: Cannot find module", then use the command npm i node-vk-bot in shell to install it.

quintendewilde commented 6 years ago

Hi,

Well indeed I forgot that part.

So in my terminal I did node

And than the following

Quintens-MacBook-Pro:vk-bot quintendewilde$ node
> import { Bot } from 'node-vk-bot'
... 
... new Bot({
...   token: 'myToken', 
...   prefix: /^Bot[\s,]/,
...   prefixOnlyInChats: true,
...   chats: [
...     1,
...     2e9 + 12
...   ],
...   api: {
.....     v: 5.38, // must be >= 5.38
.....     lang: 'en'
.....   }
... })
... 
...

Any time I press enter it just shows me 3 dots and its not like its executing anything. I probably should look more in to node and how it works.

vitalyavolyn commented 6 years ago

The line import { Bot } from 'node-vk-bot' is for TypeScript only. Since you use NodeJS, you should use

const { Bot } = require('node-vk-bot')

And then it should work.

quintendewilde commented 6 years ago

Hi! Yes, I got a response only thing is I don't think it's a working one! But still a response.

Bot {
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] },
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  options: 
   { token: 'mytoken',
     prefix: /^Bot[\s,]/,
     prefixOnlyInChats: true,
     chats: [ 1, 2000000012 ],
     api: { v: 5.38, lang: 'en' } },
  _userEvents: [],
  _stop: false }

Also my app on vk is labeled disabled? I tried sending and receiving a message but no response. Thanks for the help so far!

vitalyavolyn commented 6 years ago

You can enable application in its settings. (Settings -> Application status)

Did you use .start() method? When you define your bot, it doesn't automatically start to check for new messages.

quintendewilde commented 6 years ago

I've enabled the application on VK! :)

After creating the bot and using .start() I get ```

.start() Invalid REPL keyword


Should .start() get a value to start with? 
vitalyavolyn commented 6 years ago

start is a method of Bot class use it on your bot variable

const bot = new Bot({...})
bot.start()

maybe you should read docs first