diff --git a/commands/stats/tft.js b/commands/stats/tft.js new file mode 100644 index 0000000..9d440f3 --- /dev/null +++ b/commands/stats/tft.js @@ -0,0 +1,89 @@ +const { SlashCommandBuilder, EmbedBuilder } = require("discord.js"); +const axios = require("axios"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("tftstats") + .setDescription("Fetches TFT player stats.") + .addStringOption((option) => + option + .setName("username") + .setDescription( + "The TFT username to fetch stats for (e.g., Shitter#1234" + ) + .setRequired(true) + ), + + async execute(interaction) { + const username = interaction.options.getString("username"); + + // Convert the username by replacing "#" with "%23" + const formattedUsername = username.replace("#", "%23"); + + const apiUrl = process.env.TRACKER_API_URL; + const apiKey = process.env.TRACKER_API_KEY; + + const url = `https://${apiUrl}/tft/player/${formattedUsername}`; + + try { + await interaction.deferReply(); + + // Fetch data from the API + const response = await axios.get(url, { + headers: { + "X-API-Key": apiKey, + }, + }); + + const data = response.data; + + const statsEmbed = new EmbedBuilder() + .setColor("#ff4500") + .setTitle(`${data.username}'s TFT Stats`) + .addFields( + { + name: "🏆 Current Rank", + value: data.current_rank, + }, + { + name: "📈 LP", + value: `${data.lp}`, + }, + { + name: "🎮 Matches Played", + value: `${data.matches_played}`, + }, + { + name: "🏅 Wins", + value: `${data.wins}`, + }, + { + name: "💔 Losses", + value: `${data.losses}`, + }, + { + name: "📊 Win Percentage", + value: `${data.win_percentage}%`, + } + ) + .setTimestamp() + .setFooter({ + text: "TFT Stats API made by Ayden", + iconURL: interaction.guild.iconURL(), + }); + + return interaction.editReply({ embeds: [statsEmbed] }); + } catch (error) { + console.error("Error fetching player stats:", error); + if (error.response) { + return interaction.editReply( + `Error: ${error.response.data.message || error.response.statusText}` + ); + } else { + return interaction.editReply( + "An error occurred while fetching player stats." + ); + } + } + }, +}; diff --git a/commands/stats/valorant.js b/commands/stats/valorant.js index c3a591b..31fc460 100644 --- a/commands/stats/valorant.js +++ b/commands/stats/valorant.js @@ -29,10 +29,11 @@ module.exports = { // Convert the username by replacing "#" with "%23" const formattedUsername = username.replace("#", "%23"); - const apiKeyUrl = process.env.TRACKER_API_URL; + + const apiUrl = process.env.TRACKER_API_URL; const apiKey = process.env.TRACKER_API_KEY; - const url = `https://${apiKeyUrl}/valorant/player/${formattedUsername}/${statsType}`; + const url = `https://${apiUrl}/valorant/player/${formattedUsername}/${statsType}`; try { await interaction.deferReply();