2024-10-02 02:47:30 +01:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName("valstats")
|
|
|
|
.setDescription("Fetches Valorant player stats.")
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("username")
|
|
|
|
.setDescription(
|
|
|
|
"The Valorant username to fetch stats for (e.g., Shitter#1234)"
|
|
|
|
)
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("stats_type")
|
|
|
|
.setDescription("Type of stats to fetch")
|
|
|
|
.addChoices(
|
|
|
|
{ name: "Current Act Stats", value: "current" },
|
|
|
|
{ name: "All Acts Stats", value: "all" }
|
|
|
|
)
|
|
|
|
.setRequired(true)
|
|
|
|
),
|
|
|
|
async execute(interaction) {
|
|
|
|
const username = interaction.options.getString("username");
|
|
|
|
const statsType = interaction.options.getString("stats_type");
|
|
|
|
|
|
|
|
// Convert the username by replacing "#" with "%23"
|
|
|
|
const formattedUsername = username.replace("#", "%23");
|
2024-10-02 15:46:47 +01:00
|
|
|
const apiKeyUrl = process.env.VALORANT_API_URL;
|
2024-10-02 02:47:30 +01:00
|
|
|
const apiKey = process.env.VALORANT_API_KEY;
|
|
|
|
|
2024-10-02 15:46:47 +01:00
|
|
|
const url = `https://${apiKeyUrl}/player/${formattedUsername}/${statsType}`;
|
2024-10-02 02:47:30 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await interaction.deferReply();
|
|
|
|
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
headers: {
|
|
|
|
"X-API-Key": apiKey,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = response.data;
|
|
|
|
|
|
|
|
const statsEmbed = new EmbedBuilder()
|
|
|
|
.setColor("#0099ff")
|
|
|
|
.setTitle(`${data.username}'s Valorant Stats`)
|
2024-10-02 14:49:54 +01:00
|
|
|
.setDescription(`${data.username}'s **${data.season}** stats`)
|
2024-10-02 02:47:30 +01:00
|
|
|
.addFields(
|
|
|
|
{
|
|
|
|
name: "🏆 Current Rank",
|
|
|
|
value: data.current_rank,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "🔝 Peak Rank",
|
|
|
|
value: data.peak_rank,
|
|
|
|
},
|
2024-10-02 14:49:54 +01:00
|
|
|
{
|
|
|
|
name: "⏳ Hours Played",
|
|
|
|
value: `${data.hours_played}h`,
|
|
|
|
},
|
2024-10-02 02:47:30 +01:00
|
|
|
{
|
|
|
|
name: "🎮 Matches Played",
|
|
|
|
value: `${data.matches_played}`,
|
|
|
|
},
|
2024-10-02 14:49:54 +01:00
|
|
|
{ name: "🏅 Wins", value: `${data.wins}` },
|
|
|
|
{
|
|
|
|
name: "📊 Win Percentage",
|
|
|
|
value: `${data.win_percentage}%`,
|
|
|
|
},
|
|
|
|
{ name: "⚔️ Kills", value: `${data.kills}` },
|
2024-10-02 02:47:30 +01:00
|
|
|
{
|
|
|
|
name: "📈 K/D Ratio",
|
|
|
|
value: `${data.kd_ratio}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "🎯 Headshot Percentage",
|
|
|
|
value: `${data.headshot_percentage}%`,
|
|
|
|
},
|
|
|
|
{
|
2024-10-02 14:49:54 +01:00
|
|
|
name: "💯 Tracker Score",
|
|
|
|
value: `${data.tracker_score}/1000`,
|
2024-10-02 02:47:30 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.setTimestamp()
|
|
|
|
.setFooter({
|
2024-10-02 14:49:54 +01:00
|
|
|
text: "Valorant Stats API made by Ayden",
|
2024-10-02 02:47:30 +01:00
|
|
|
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."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|