Cannot register commands globally

I am trying to register my slash commands to every server that my bot is in, but for some reason I can't. This code worked before it suddenly decided not working. I don't get any errors, it just halts the execution like it is still waiting for the response. My bot is in only two servers at the moment, I have tried kicking it from both of them and inviting back with application.commands and bot permissions. I have also tried using client.application.commands.set() instead of rest.put().

Here is a part of my code:
try {
    await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), {
      body: [],
    });

    const allGuildIds = await client.guilds.cache.map((guild) => guild.id);

    await allGuildIds.forEach((guildId) => {
      rest.put(
        Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId),
        {
          body: [],
        }
      );
    });

    console.log(
      `πŸ”„ Started refreshing ${commands.length} application commands...`
    );

    // THIS WORKS
    const data = await rest.put(
      Routes.applicationGuildCommands(
        process.env.CLIENT_ID,
        process.env.GUILD_ID
      ),
      {
        body: commands,
      }
    );

    // THIS DOES NOT WORK
    // const data = await rest.put(
    //   Routes.applicationCommands(process.env.CLIENT_ID),
    //   {
    //     body: commands,
    //   }
    // );

    console.log(
      `βœ… Successfully refreshed ${data.length} application commands!`
    );
  } catch (err) {
    console.log(`There was an error: ${err}`);
  }


Also, if there is a better way to clear the application commands from every guild before adding the new ones, please let me know.
Was this page helpful?