not-an-aardvark / snoowrap

A JavaScript wrapper for the reddit API
MIT License
1.01k stars 125 forks source link

getSubreddit(name).getNew({limit}) doesn't work #385

Closed ArturFortunato closed 10 months ago

ArturFortunato commented 10 months ago

here's my code

async function test() {
  const limit = 10;
  // Retrieve posts from the specified subreddit made in the last 15 minutes
  const posts = await reddit.getSubreddit(subredditName).getNew({limit: 10});

  console.log(posts.length);
}

test().then(() => console.log("DONE"));

Executing this yields

return target.apply(this, arguments);
                      ^
TypeError: Cannot read properties of undefined (reading 'after')
    at .../node_modules/snoowrap/dist/objects/Listing.js:233:47
   ...

The problem goes away if I remove the limit filter, but that returns too many posts, and I want the new ones only. Adding after: "" doesn't help.

How can I get the new posts?

ArturFortunato commented 10 months ago

Found the problem, authentication was incorrect. Maybe it could have a clearer error message :)