dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

Wiki isn't a Constructor #32

Closed Carbowix closed 7 years ago

Carbowix commented 7 years ago

I was trying to build a bot that gets from wiki a simple summary about the User Search.

Everything is good, but gives a error saying Wiki isnt Constructor. Whats that?.

{ var Wiki = require('wikijs'); var term = args.join(' '); if (!term) { msg.channel.sendMessage("Please Enter a Term to Search for it in the Wiki."); return; } msg.channel.sendMessage(":mag_right: Searching for your Term..").then(m => { new Wiki().search(term, 1).then(function(data) { new Wiki().page(data.results[0]).then(function(page) { page.summary().then(function(summary) { var sumText = summary.toString().split('\n'); var continuation = function() { var paragraph = sumText.shift(); msg.channel.sendMessage(paragraph); console.log(paragraph); console.log(sumText); if (paragraph) { m.edit(paragraph); msg.channel.sendMessage(paragraph); msg.channel.sendMessage(sumText); } msg.channel.sendMessage(paragraph); }; continuation(); }); }); }, function(err) { m.edit(err); }); }) };

Thank you if you helped ^^

dijs commented 7 years ago

Try converting all the new Wiki()'s to Wiki().

Wiki is not a class anymore. It is a function which returns an object with other functions.

Also, to help remember this, I normally would use lower case when using and requiring.

var wiki = require('wikijs');
wiki().search('hello')...
Carbowix commented 7 years ago

Did what you told me, but now it says wiki isn't a function ._.

var wiki = require('wikijs'); var term = args.join(' '); if (!term) { msg.channel.sendMessage("Please Enter a Term to Search for it in the Wiki."); return; } msg.channel.sendMessage(":mag_right: Searching for your Term..").then(m => { wiki().search(term, 1).then(function(data) { wiki().page(data.results[0]).then(function(page) { page.summary().then(function(summary) { var sumText = summary.toString().split('\n'); var continuation = function() { var paragraph = sumText.shift(); if (paragraph) { m.edit(paragraph); msg.channel.sendMessage(paragraph); } }; continuation(); }); }); }, function(err) { m.edit(err); }); }) Weird though. I wonder whats wrong ;c

dijs commented 7 years ago

Try var wiki = require('wikijs').default;

Carbowix commented 7 years ago

Thanks it worked Finally :D

dijs commented 7 years ago

Great!