'ghost command issue Discord.js

client.once('ready', () => {
    console.log('My Bot is Online!');
    const guildid='<My server id>';
    const guild=client.guilds.cache.get(guildid);
    let commandy;
    if(guild){
        commandy = guild.commands;
    }else{
        commandy=client.application.commands;
    }
    commandy?.create({
        name:"we",
        description: "This is a test!",   
    })
});
client.on("interactionCreate",async (interaction) => {
    if(!interaction.isCommand){
        return;
    }
    const {commandName, options} = interaction;
    if(commandName=="test"){
        interaction.reply({
            content: 'something something idk',
            ephemeral: true
        })
    }
})

I had a command named "text" and then i replaced it with "we" my problem is that it stayed after i reset it. How can i delete all prefius commands and then recreate them newly so that the old commands don't become ghost commands



Solution 1:[1]

You can delete that command with

 client.application.commands.fetch('ENTER_COMMAND_ID_HERE').then( (command) => {
     console.log(`Fetched command ${command.name}`)
     command.delete()
     console.log(`Deleted command ${command.name}`)
 }).catch(console.error);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lavency