const commands = [ new SlashCommandBuilder() .setName('odds') .setDescription('Get live odds for a team') .addStringOption(opt => opt.setName('team').setDescription('Team name').setRequired(true) ), new SlashCommandBuilder() .setName('scores') .setDescription('Show all live scores') .addStringOption(opt => opt.setName('sport').setDescription('Filter by sport (e.g. soccer)') ),];// Register commands on bot startupconst rest = new REST().setToken(process.env.DISCORD_TOKEN!);await rest.put( Routes.applicationCommands(process.env.DISCORD_CLIENT_ID!), { body: commands.map(c => c.toJSON()) });
Uses getScores() — the lightweight endpoint optimized for frequent polling:
if (interaction.commandName === 'scores') { await interaction.deferReply(); const sport = interaction.options.getString('sport') || undefined; const data = await ff.getScores({ sport }); if (!data.scores || data.scores.length === 0) { await interaction.editReply('No live games right now.'); return; } const embed = new EmbedBuilder() .setTitle('🔴 Live Scores') .setColor(0xFF0000); // Show up to 10 games for (const game of data.scores.slice(0, 10)) { embed.addFields({ name: `${game.home_team} vs ${game.away_team}`, value: `**${game.score.home} - ${game.score.away}** • ${game.league}`, }); } await interaction.editReply({ embeds: [embed] });}