I’m looping over an array with 2 items, where it should be giving me one item in the loop. However it just gives the entire array after looping.
[
{
status: 200,
statusText: 'OK',
headers: AxiosHeaders {
date: 'Fri, 17 Mar 2023 00:45:58 GMT',
'content-type': 'application/json',
'transfer-encoding': 'chunked',
connection: 'close',
'set-cookie': [Array],
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
'x-ratelimit-bucket': 'f7ead6a7674e5a323d93786263b66cb1',
'x-ratelimit-limit': '50',
'x-ratelimit-remaining': '49',
'x-ratelimit-reset': '1679013958.858',
'x-ratelimit-reset-after': '0.019',
via: '1.1 google',
'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'report-to': '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=xKTf0hVCUg0G348XsfiUpPVF2S%2FRtHec4bcEjhc2ZHidVhzQ%2F8aZz1Gxu6IOlbC925BGHbB3cLCMHWyYyW4fOq9qmEdBHP3OVkm0kiQEyNOvtaoP%2BfslLDUdLgrn"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
'x-content-type-options': 'nosniff',
server: 'cloudflare',
'cf-ray': '7a91375a5ce4ad33-ATL'
},
config: {
transitional: [Object],
adapter: [Array],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [AxiosHeaders],
baseURL: 'https://discord.com/api/v10',
method: 'get',
url: '/channels/1071951518946828429',
data: undefined
},
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: true,
socket: [TLSSocket],
_header: 'GET /api/v10/channels/1071951518946828429 HTTP/1.1rn' +
'Accept: application/json, text/plain, */*rn' +
'Authorization: Bot +
'User-Agent: axios/1.3.4rn' +
'Accept-Encoding: gzip, compress, deflate, brrn' +
'Host: discord.comrn' +
'Connection: closern' +
'rn',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/v10/channels/1071951518946828429',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'discord.com',
protocol: 'https:',
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
data: {
id: '1071951518946828429',
last_message_id: '1086060000423706675',
type: 0,
name: 'free-games',
position: 18,
flags: 0,
parent_id: '753760260266655826',
topic: null,
guild_id: '753760255900516402',
permission_overwrites: [Array],
rate_limit_per_user: 0,
nsfw: false
}
},
{
status: 200,
statusText: 'OK',
headers: AxiosHeaders {
date: 'Fri, 17 Mar 2023 00:45:59 GMT',
'content-type': 'application/json',
'transfer-encoding': 'chunked',
connection: 'close',
'set-cookie': [Array],
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
'x-ratelimit-bucket': 'f7ead6a7674e5a323d93786263b66cb1',
'x-ratelimit-limit': '50',
'x-ratelimit-remaining': '49',
'x-ratelimit-reset': '1679013959.102',
'x-ratelimit-reset-after': '0.019',
via: '1.1 google',
'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'report-to': '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=%2BMv3IziW0ZzOch3ojFNTbd1MUrjAlXAQZoWuHmCbSPqVYGNB3h2Rt%2Fdc7z1B%2BIpSk%2BQOJkE0j%2By%2BXHZFjD4PejweFa4ywleT1aZdbKRe%2B4PlZGa7yhU98697pOH0"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
'x-content-type-options': 'nosniff',
server: 'cloudflare',
'cf-ray': '7a91375beb58b032-ATL'
},
config: {
transitional: [Object],
adapter: [Array],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [AxiosHeaders],
baseURL: 'https://discord.com/api/v10',
method: 'get',
url: '/channels/1071972385831526420',
data: undefined
},
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: true,
socket: [TLSSocket],
_header: 'GET /api/v10/channels/1071972385831526420 HTTP/1.1rn' +
'Accept: application/json, text/plain, */*rn' +
'Authorization: Bot +
'User-Agent: axios/1.3.4rn' +
'Accept-Encoding: gzip, compress, deflate, brrn' +
'Host: discord.comrn' +
'Connection: closern' +
'rn',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/v10/channels/1071972385831526420',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'discord.com',
protocol: 'https:',
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
data: {
id: '1071972385831526420',
last_message_id: '1086060739615273091',
type: 0,
name: 'free-games',
position: 32,
flags: 0,
parent_id: '983858995691405322',
topic: null,
guild_id: '983858506140639352',
permission_overwrites: [Array],
rate_limit_per_user: 0,
nsfw: false
}
},
]
There are two items this array and I’m trying to loop over them using this code:
/**
* @param {Interaction[]} channels
*/
async sendFreeGames(...channels) {
const games = await this.#createEpicFreeGamesEmbeds();
const buttons = await this.#createEpicFreeButtons();
if (games.length === 0) return;
for (const channel of channels) {
// @ts-ignore
const discordAxios = axios.create({ baseURL: 'https://discord.com/api/v10', headers: { Authorization: `Bot ${process.env.DISCORD_TOKEN}`,},});
console.log(channel.data.type)
discordAxios.post(`/channels/${channel.data.id}/messages`, { embeds: games, components: buttons });
}
}
}
However when looping and accessing channel it just returns the whole array instead of each item in the array leading to channel.data.typebeing undefined but channel[0].data.type being valid. I’ve been trying to solve this for 4 hours with no luck. Any help would be appreciated.