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)
|
2024-10-06 00:25:11 +01:00
|
|
|
)
|
|
|
|
.addBooleanOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("include_weapons")
|
|
|
|
.setDescription("Include top weapons stats?")
|
|
|
|
.setRequired(false)
|
|
|
|
)
|
|
|
|
.addBooleanOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("include_maps")
|
|
|
|
.setDescription("Include top maps stats?")
|
|
|
|
.setRequired(false)
|
|
|
|
)
|
|
|
|
.addBooleanOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("include_roles")
|
|
|
|
.setDescription("Include roles stats?")
|
|
|
|
.setRequired(false)
|
2024-10-02 02:47:30 +01:00
|
|
|
),
|
|
|
|
async execute(interaction) {
|
2024-10-06 00:59:17 +01:00
|
|
|
// Immediately defer the reply
|
|
|
|
await interaction.deferReply();
|
|
|
|
|
2024-10-02 02:47:30 +01:00
|
|
|
const username = interaction.options.getString("username");
|
2024-10-06 00:56:33 +01:00
|
|
|
|
|
|
|
// Check if username contains '#'
|
|
|
|
if (!username.includes("#")) {
|
2024-10-06 00:59:17 +01:00
|
|
|
return interaction.editReply({
|
2024-10-06 00:56:33 +01:00
|
|
|
content:
|
|
|
|
"Error: Please include your tag in the username (e.g., Shitter#1234).",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-02 02:47:30 +01:00
|
|
|
const statsType = interaction.options.getString("stats_type");
|
2024-10-06 00:25:11 +01:00
|
|
|
const includeWeapons = interaction.options.getBoolean("include_weapons");
|
|
|
|
const includeMaps = interaction.options.getBoolean("include_maps");
|
|
|
|
const includeRoles = interaction.options.getBoolean("include_roles");
|
2024-10-02 02:47:30 +01:00
|
|
|
|
|
|
|
// Convert the username by replacing "#" with "%23"
|
|
|
|
const formattedUsername = username.replace("#", "%23");
|
2024-10-04 03:51:14 +01:00
|
|
|
|
|
|
|
const apiUrl = process.env.TRACKER_API_URL;
|
2024-10-03 16:37:44 +01:00
|
|
|
const apiKey = process.env.TRACKER_API_KEY;
|
2024-10-02 02:47:30 +01:00
|
|
|
|
2024-10-05 23:32:30 +01:00
|
|
|
// Use statsType for the main URL
|
2024-10-04 03:51:14 +01:00
|
|
|
const url = `https://${apiUrl}/valorant/player/${formattedUsername}/${statsType}`;
|
2024-10-02 02:47:30 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
headers: {
|
|
|
|
"X-API-Key": apiKey,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = response.data;
|
|
|
|
|
2024-10-05 23:32:30 +01:00
|
|
|
// Create the embed for player stats
|
2024-10-02 02:47:30 +01:00
|
|
|
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",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: data.current_rank,
|
2024-10-02 02:47:30 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "🔝 Peak Rank",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.peak_rank} (${data.peak_rank_episode})`,
|
2024-10-02 02:47:30 +01:00
|
|
|
},
|
2024-10-02 14:49:54 +01:00
|
|
|
{
|
|
|
|
name: "⏳ Hours Played",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.playtime_hours}h`,
|
2024-10-02 14:49:54 +01:00
|
|
|
},
|
2024-10-02 02:47:30 +01:00
|
|
|
{
|
|
|
|
name: "🎮 Matches Played",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.matches_played}`,
|
2024-10-02 02:47:30 +01:00
|
|
|
},
|
2024-10-06 00:25:11 +01:00
|
|
|
{ name: "🏅 Wins", value: `${data.wins}` },
|
2024-10-02 14:49:54 +01:00
|
|
|
{
|
|
|
|
name: "📊 Win Percentage",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.win_percentage}%`,
|
2024-10-02 14:49:54 +01:00
|
|
|
},
|
2024-10-06 00:25:11 +01:00
|
|
|
{ name: "⚔️ Kills", value: `${data.kills}` },
|
2024-10-02 02:47:30 +01:00
|
|
|
{
|
|
|
|
name: "📈 K/D Ratio",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.kd_ratio}`,
|
2024-10-02 19:58:07 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "📊 ACS",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.acs}`,
|
2024-10-02 02:47:30 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "🎯 Headshot Percentage",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.headshot_percentage}%`,
|
2024-10-02 02:47:30 +01:00
|
|
|
}
|
2024-10-02 18:26:49 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Add the Tracker Score field only if statsType is "current"
|
|
|
|
if (statsType === "current") {
|
|
|
|
statsEmbed.addFields({
|
|
|
|
name: "💯 Tracker Score",
|
2024-10-06 00:25:11 +01:00
|
|
|
value: `${data.tracker_score}/1000`,
|
2024-10-02 02:47:30 +01:00
|
|
|
});
|
2024-10-02 18:26:49 +01:00
|
|
|
}
|
|
|
|
|
2024-10-06 00:25:11 +01:00
|
|
|
const embeds = [statsEmbed];
|
|
|
|
|
|
|
|
// Optional weapons embed
|
|
|
|
if (includeWeapons) {
|
|
|
|
const weaponsEmbed = new EmbedBuilder()
|
|
|
|
.setColor("#0099ff")
|
|
|
|
.setTitle(`${data.username}'s Top Weapons`)
|
|
|
|
.setDescription(`${data.username}'s top weapons stats:`);
|
|
|
|
|
|
|
|
data.top_weapons.forEach((weapon) => {
|
|
|
|
weaponsEmbed.addFields({
|
|
|
|
name: weapon.name,
|
|
|
|
value:
|
|
|
|
`Type: ${weapon.weapon_type}\n` +
|
|
|
|
`Kills: ${weapon.kills}\n` +
|
|
|
|
`Accuracy: ${weapon.accuracy.join(", ")}\n`,
|
|
|
|
inline: true,
|
|
|
|
});
|
2024-10-05 23:32:30 +01:00
|
|
|
});
|
|
|
|
|
2024-10-06 00:25:11 +01:00
|
|
|
embeds.push(weaponsEmbed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optional maps embed
|
|
|
|
if (includeMaps) {
|
|
|
|
const mapsEmbed = new EmbedBuilder()
|
|
|
|
.setColor("#0099ff")
|
|
|
|
.setTitle(`${data.username}'s Top Maps`)
|
|
|
|
.setDescription(`${data.username}'s top maps stats:`);
|
|
|
|
|
|
|
|
data.top_maps.forEach((map) => {
|
|
|
|
mapsEmbed.addFields({
|
|
|
|
name: map.name,
|
|
|
|
value: `Win Percentage: ${map.win_percentage}%\nMatches: ${map.matches}`,
|
|
|
|
inline: true,
|
|
|
|
});
|
2024-10-05 23:32:30 +01:00
|
|
|
});
|
|
|
|
|
2024-10-06 00:25:11 +01:00
|
|
|
embeds.push(mapsEmbed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optional roles embed
|
|
|
|
if (includeRoles) {
|
|
|
|
const rolesEmbed = new EmbedBuilder()
|
|
|
|
.setColor("#0099ff")
|
|
|
|
.setTitle(`${data.username}'s Roles`)
|
|
|
|
.setDescription(`${data.username}'s performance by role:`);
|
|
|
|
|
|
|
|
data.roles.forEach((role) => {
|
|
|
|
rolesEmbed.addFields({
|
|
|
|
name: role.name,
|
|
|
|
value:
|
|
|
|
`Win Rate: ${role.win_rate}%\n` +
|
|
|
|
`KDA: ${role.kda}\n` +
|
|
|
|
`Wins: ${role.wins}\n` +
|
|
|
|
`Losses: ${role.losses}\n` +
|
|
|
|
`Kills: ${role.kills}\n` +
|
|
|
|
`Deaths: ${role.deaths}\n` +
|
|
|
|
`Assists: ${role.assists}`,
|
|
|
|
inline: true,
|
|
|
|
});
|
2024-10-05 23:32:30 +01:00
|
|
|
});
|
2024-10-06 00:25:11 +01:00
|
|
|
|
|
|
|
embeds.push(rolesEmbed);
|
|
|
|
}
|
2024-10-05 23:32:30 +01:00
|
|
|
|
2024-10-02 18:26:49 +01:00
|
|
|
statsEmbed.setTimestamp().setFooter({
|
|
|
|
text: "Valorant Stats API made by Ayden",
|
|
|
|
iconURL: interaction.guild.iconURL(),
|
|
|
|
});
|
2024-10-02 02:47:30 +01:00
|
|
|
|
2024-10-06 00:25:11 +01:00
|
|
|
return interaction.editReply({ embeds });
|
2024-10-02 02:47:30 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching player stats:", error);
|
|
|
|
if (error.response) {
|
2024-10-06 00:59:17 +01:00
|
|
|
return interaction.editReply({
|
2024-10-06 00:56:33 +01:00
|
|
|
content: `Error: ${
|
|
|
|
error.response.data.message || error.response.statusText
|
|
|
|
}`,
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
2024-10-02 02:47:30 +01:00
|
|
|
} else {
|
2024-10-06 00:59:17 +01:00
|
|
|
return interaction.editReply({
|
2024-10-06 00:56:33 +01:00
|
|
|
content: "An error occurred while fetching player stats.",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
2024-10-02 02:47:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|