Skip to content

Commit

Permalink
moved hypixel command
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Aug 7, 2022
1 parent 2cb8757 commit 09e0cdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
File renamed without changes.
31 changes: 17 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const hypixelLimiter = new Limit(120, 60 * 1000);
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.commands = new Collection();
client.msgCommands = new Collection();
client.guildCommands = new Collection();

getCommands("./commands", (command) => {
client.commands.set(command.data.name, command);
Expand Down Expand Up @@ -61,20 +62,18 @@ client.once("ready", async () => {

await rest.put(
Routes.applicationGuildCommands(process.env.id, process.env.guildid),
{ body: [...client.guildCommands] },
{ body: client.guildCommands.map(command => command.data.toJSON()) },
);

const commandValues = new Set((await client.application.commands.fetch()).map(command => command.name));

for(const command of client.commands.map(command => command.data.name)) {
if(!commandValues.has(command)) {
await rest.put(
Routes.applicationCommands(process.env.id),
{ body: [...client.commands.values()] },
);
console.log('Successfully reloaded application (/) commands.');
return;
}
const commands = new Set(client.commands.map(command => command.data.name));
if(commandValues.size !== commands.size || ![...commandValues].every(command => commands.has(command))) {
await rest.put(
Routes.applicationCommands(process.env.id),
{ body: client.commands.map(command => command.data.toJSON()) },
);
console.log('Successfully reloaded application (/) commands.');
return;
}

console.log('No (/) commands to reload.');
Expand All @@ -98,16 +97,20 @@ client.on("messageCreate", async message => {

client.on("interactionCreate", async interaction => {
if(interaction.type === InteractionType.ApplicationCommand) {
if (!client.commands.has(interaction.commandName)) return;
if (!client.commands.has(interaction.commandName) && !client.guildCommands.has(interaction.commandName)) return;
await interaction.deferReply();
try {
await client.commands.get(interaction.commandName).execute(interaction);
if(client.commands.has(interaction.commandName)) {
await client.commands.get(interaction.commandName).execute(interaction);
} else {
await client.guildCommands.get(interaction.commandName).execute(interaction);
}
} catch (error) {
console.error(error);
await interaction.editReply({ content: "There was an error while executing this command!", ephemeral: true });
}
} else if(interaction.isSelectMenu()) {
await client.commands.get("hypixel").execute(interaction);
await client.guildCommands.get("hypixel").execute(interaction);
}
});

Expand Down

0 comments on commit 09e0cdb

Please sign in to comment.