Skip to content

Commit

Permalink
public
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstech committed Oct 22, 2023
1 parent a2fb61e commit 72033b2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions commands/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const fetch = require("node-fetch");
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");


module.exports = {
data: new SlashCommandBuilder()
.setName("check")
.setDescription("Check if a domain is available.")
.addStringOption((option) =>
option
.setName("subdomain")
.setDescription("The subdomain to check.")
.setRequired(true),
),
async execute(interaction) {
const subdomain = interaction.options
.getString("subdomain")
.toLowerCase();
// get the guild id from the interaction


if (subdomain.length < 2 || subdomain.length > 64) {
const sadEmbed = new EmbedBuilder()
.setDescription("The subdomain length must be between 2 and 64 characters.")
.setColor("#0096ff");
return await interaction.reply({ embeds: [sadEmbed] });
}

try {
const response = await fetch(
`https://api.github.com/repos/is-a-dev/register/contents/domains/${subdomain}.json`,
{
headers: {
"User-Agent": "is-a-dev-bot",
},
cache: "no-cache",
},
);

if (response.status === 404) {
const happyEmbed = new EmbedBuilder()
.setDescription(`Congratulations, ${subdomain}.is-a.dev is available!`)
.setColor("#0096ff");
await interaction.reply({ embeds: [happyEmbed] }
);
} else {
const sadEmbed = new EmbedBuilder()
.setDescription(`Sorry, ${subdomain}.is-a.dev is taken!`)
.setColor("#0096ff");
await interaction.reply({ embeds: [sadEmbed] }
);
}
} catch (error) {
console.error(
"Error occurred while checking domain availability:",
error,
);
const sadEmbed = new EmbedBuilder()
.setDescription("An error occurred while checking domain availability.")
.setColor("#0096ff");
await interaction.reply({ embeds: [sadEmbed]
});
}
},
};

0 comments on commit 72033b2

Please sign in to comment.