Slash Commands

I'm having trouble restricting the slash commands so that they only appear on the servers where the bot is installed. They even appear in users' DMs.

Can you please help me?

Below is my command registration code:
import 'dotenv/config';

import { REST, Routes, ApplicationCommandOptionType } from "discord.js";

const commandsGlobal = [
    {
        name: 'invite',
        description: 'Receba um link de convite para adicionar o bot a outros servidores',
    },
    {
        name: "wows-usuario",
        description: "Exibe informações do usuário",
        options: [{
            name: "nome",
            description: "Digite o nome do usuário",
            type: ApplicationCommandOptionType.String,
            required: "true"
        }]
    }
];

const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);

(async () => {
    try {
        console.log("Registrando comandos globais...");

        // Registro dos comandos globais
        await rest.put(
            Routes.applicationCommands(process.env.CLIENT_ID),
            { body: commandsGlobal } // Aqui está a variável `commandsGlobal`
        );

        console.log("Comandos globais registrados com sucesso!");
    } catch (error) {
        console.log(`Há erro(s): ${error}`);
    }
})();
Was this page helpful?