OceanicJS / Oceanic

A NodeJS library for interfacing with Discord.
https://oceanic.ws
MIT License
269 stars 25 forks source link

"data.map is not a function" when using REST/Channels.getPollAnswerUsers method #149

Closed LonelyDeathVGX closed 7 months ago

LonelyDeathVGX commented 7 months ago

Hello 👋 While I was testing the version 1.10.0 to see which users voted the answers from a poll, I used this code

const data = await client.rest.channels.getPollAnswerUsers(
  "CHANNEL_ID",
  "MESSAGE_ID",
  1
);

But when I was executing that code, I saw this error

TypeError: data.map is not a function

I did a custom request to see what was the response, so I used this code

const data = await client.rest.authRequest({
  method: "GET",
  path: "/channels/CHANNEL_ID/polls/MESSAGE_ID/answers/1",
});
{
  users: [
    // Discord API User Objects
  ]
}

So, from this line

https://github.com/OceanicJS/Oceanic/blob/f5123cae148553a0c7113afb3adc85ae2a73f0da/lib/routes/Channels.ts#L825

I think it should be changed to this due to response body being an object with an array of users inside

const users = data.users.map(user => this.#manager.client.users.update(user));

Thanks for reading

DonovanDMC commented 7 months ago

Fixed in 1.10.1-polls.4f7666b2