Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit not working #4

Closed
Axecident opened this issue Sep 8, 2016 · 4 comments
Closed

limit not working #4

Axecident opened this issue Sep 8, 2016 · 4 comments

Comments

@Axecident
Copy link

I have tried the following piece of code

if(message.content.startsWith ("/google")) { var lastmsg = message var msgArray = message.content.split('/google ') var searchoptions = { query: msgArray[1], host: 'www.google.com.au', lang: 'en', limit: 1 }; var firstSearch = false; scraper.search(searchoptions, function(err, url) { //this is called for each result if(err) throw err; if(firstSearch == false) { console.log(url) message.channel.sendMessage(url).catch(console.error); firstSearch = true; } });
As you can see in that code i made a creative work-around.

But I shouldn't have had to do that, the problem is that even though i set limit to 1 it still didn't change it to 1.

I even thought maybe it's adding a zero on the end? making it 10 anyway? So i changed it to 01 but that didn't work either.

Is there something I'm doing wrong?

P.S.
Ignore the if statement about message.content and anything else about messages. That's there because i am using this inside of a discord bot.

@thibauts
Copy link
Owner

thibauts commented Sep 8, 2016

Please post formatted code. It's really difficult to read as is. Thanks

@Axecident
Copy link
Author

The code was formatted when I posted it. It was also inserted into the post via "Insert code".

The best I can do to make it more view-able is put it in a text file.
limit_problem.txt.txt

@thibauts thibauts closed this as completed Oct 7, 2016
@thibauts
Copy link
Owner

thibauts commented Oct 7, 2016

The best you can do is click on "Styling with Markdown ..." below the comment box and learn how to style comments on github.

If you don't bother to do that don't expect me to bother considering your issue.

@ElDondo
Copy link

ElDondo commented Jan 4, 2017

I have had the same problem while coding my Discord bot.. it always returned 9 urls even though I had set my limit to 1. I was trying to fix it by making small changes in the node_modules/google-search-scraper/index.js and made it work by adding

newResults.length = 1;

to the file just before

newResults.forEach(function(result) {
      callback(null, result);
    });

And then it respected the limit I set in my Discord bot code.
Don't ask me why this works though, I was just trying some things and apparently this worked :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants