You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a little Discord Bot App that fetches box score data from our league. I'm currently returning scores based on a hard coded matchup/scoring period. Does anybody know how to get the matchup / scoring period dynamically based on the current week? Here is my code:
I created an endpoint to fetch the league data from the base URL and pull from the scoringPeriodId there. Then inside my functions if I dont pass a week into them - I usually run some logic to pull this data.
const getTeams = async (week, year = seasonId) => {
let scoringPeriod;
if (!week) {
scoringPeriod = await getCurrentWeek();
} else {
scoringPeriod = week;
}
...
};
I wrote a little Discord Bot App that fetches box score data from our league. I'm currently returning scores based on a hard coded matchup/scoring period. Does anybody know how to get the matchup / scoring period dynamically based on the current week? Here is my code:
`const { Client } = require('espn-fantasy-football-api/node');
const { getName } = require('./player-mapping');
require('dotenv').config();
const leagueId = process.env.espn_leagueid;
const espnS2 = process.env.espn_espnS2;
const SWID = process.env.espn_swid;
const seasonId = process.env.espn_seasonid;
const myClient = new Client({ leagueId });
myClient.setCookies({ espnS2, SWID });
async function getEspnData() {
const getScores = await myClient.getBoxscoreForWeek({
seasonId,
matchupPeriodId: 1,
scoringPeriodId: 1
});
const matchupData = createEmbedFields(getScores);
const embedded = embedData(matchupData);
return embedded;
}
function createEmbedFields(boxScore) {
const matchupArrayData = boxScore.map(scores => {
const awayTeamId = getName(scores.awayTeamId.toString());
const homeTeamId = getName(scores.homeTeamId.toString());
const awayPoints = scores.awayScore.toString();
const homePoints = scores.homeScore.toString();
return [
{
name: awayTeamId,
value: awayPoints,
inline: true
},
{
name: homeTeamId,
value: homePoints,
inline: true
},
{
name: '\u200B',
value: '\u200B'
}
]
})
.flat();
return matchupArrayData;
}
function embedData(teamData) {
const fflEmbed = {
color: 0x0099ff,
title: 'Current Scores',
fields: teamData,
timestamp: new Date(),
};
return { embeds: [fflEmbed] }
}
module.exports = {
getEspnData,
embedData
};`
The text was updated successfully, but these errors were encountered: