#Slash Commands

17 messages · Page 1 of 1 (latest)

smoky barn
#

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}`);
    }
})();
frail gardenBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
void rivet
#

specify the context in the command payload

lucid latchBOT
#

discord Application Commands - Create Global Application Command POST /applications/\application.id/commands
Create a new global command. Returns 201 if a command with the same name does not already exist, or a 200 if it does (in which case the previous command will be overwritten). Both responses include an application command object.
read more

void rivet
#

contexts

smoky barn
void rivet
#

np, glad it worked

smoky barn
# void rivet np, glad it worked

Another question please.
Do you know why the command below does not work when the user executes the slash command in DM?
```js
case "invite":
//const inviteLink = https://discord.com/oauth2/authorize?client_id=${client.user.id}&scope=bot&permissions=8;
const inviteLink = https://discord.com/application-directory/1170039088791965706;
await interaction.reply(> Aqui está o link para adicionar o bot ao seu servidor: ${inviteLink});
break;

void rivet
#

"does not work" surfaces how?

#

does it reach that code?

smoky barn
void rivet
#

does it reach that portion of code? (try putting a log there)

#

if not, there might be some part of your command handler like "in cached guild" guards that prevents execution

smoky barn
#
   if (!interaction.isChatInputCommand()) return;

    switch(interaction.commandName) {
        case "invite":
            //const inviteLink = `https://discord.com/oauth2/authorize?client_id=${client.user.id}&scope=bot&permissions=8`;
            const inviteLink = `https://discord.com/application-directory/1170039088791965706`;
            await interaction.reply(`> Here is the link to add the bot to your server: ${inviteLink}`);
            break;  
void rivet
#

it should be a chat input command still, but it won't be in the context of a guild/cached guild if that's something you expect/enforce in code

lucid latchBOT