mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-25 02:05:56 +00:00
val stats: check whether the user included # when using the comand or no, handle it after deferring the msg
This commit is contained in:
parent
d29050fa1e
commit
8a45ac22de
1 changed files with 6 additions and 5 deletions
|
@ -42,11 +42,14 @@ module.exports = {
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
// Immediately defer the reply
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
const username = interaction.options.getString("username");
|
const username = interaction.options.getString("username");
|
||||||
|
|
||||||
// Check if username contains '#'
|
// Check if username contains '#'
|
||||||
if (!username.includes("#")) {
|
if (!username.includes("#")) {
|
||||||
return interaction.followUp({
|
return interaction.editReply({
|
||||||
content:
|
content:
|
||||||
"Error: Please include your tag in the username (e.g., Shitter#1234).",
|
"Error: Please include your tag in the username (e.g., Shitter#1234).",
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
|
@ -68,8 +71,6 @@ module.exports = {
|
||||||
const url = `https://${apiUrl}/valorant/player/${formattedUsername}/${statsType}`;
|
const url = `https://${apiUrl}/valorant/player/${formattedUsername}/${statsType}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await interaction.deferReply();
|
|
||||||
|
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"X-API-Key": apiKey,
|
"X-API-Key": apiKey,
|
||||||
|
@ -203,14 +204,14 @@ module.exports = {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching player stats:", error);
|
console.error("Error fetching player stats:", error);
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
return interaction.followUp({
|
return interaction.editReply({
|
||||||
content: `Error: ${
|
content: `Error: ${
|
||||||
error.response.data.message || error.response.statusText
|
error.response.data.message || error.response.statusText
|
||||||
}`,
|
}`,
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return interaction.followUp({
|
return interaction.editReply({
|
||||||
content: "An error occurred while fetching player stats.",
|
content: "An error occurred while fetching player stats.",
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue