AlexzanderFlores / WOKCommands

130 stars 61 forks source link

Slash commands are not accepting arguments #174

Open 4Lajf opened 2 years ago

4Lajf commented 2 years ago

The same exact command works diferently between legacy and slash options. https://cdn.discordapp.com/attachments/818363058656509993/895043214933893171/unknown.png The code is copied from the docs and it's as follows:

module.exports = {
  category: 'Testing', // Required for slash commands
  description: 'Displays your name and age', // Required for slash commands

  slash: 'both', // Support both legacy and slash command syntax
  testOnly: true, // Ensure you have test servers setup

  minArgs: 2,
  expectedArgs: '<name> <age>',

  callback: ({ message, interaction, args }) => {
    // Destructure the name and age from the args array
    const [name, age] = args

    // Create a string that is used in either command syntax
    const reply = `Hello my name is ${name} and I am ${age} years old.`

    // The message property will be undefined if the command is ran
    // as a slash command. It is encouraged to check if 'message' or
    // 'interaction' exists before interacting with them.
    if (message) {
      message.reply({
        content: reply
      })
    }

    // The interaction property will be undefined if the command is
    // ran as a legacy command. It is encouraged to check if 'message' or
    // 'interaction' exists before interacting with them.
    if (interaction) {
      interaction.reply({
        content: reply
      })
    }
  }
}

Which is really weird bcs the last example in the docs works

JesseMader commented 2 years ago

Ran into this issue as well, my workaround was to use interaction.options.getString('argument value'). So for the above it would be something like.

callback: ({ message, interaction, args }) => {
    // Destructure the name and age from the args array
    const name = interaction.options.getString('name');
    const age = interaction.options.getString('age');

    // Create a string that is used in either command syntax
    const reply = `Hello my name is ${name} and I am ${age} years old.`

    // The message property will be undefined if the command is ran
    // as a slash command. It is encouraged to check if 'message' or
    // 'interaction' exists before interacting with them.
    if (message) {
      message.reply({
        content: reply
      })
    }
GamerBossHarmon commented 2 years ago

to get this to work you need to add this to your code for example here is what I used for my kick command

options: [
      {
        name: 'user',// This has to be lowercase
        description: 'The User you want to kick',
        required: true,
        type: 6, 
      }, {
        name: 'reason',// This has to be lowercase
        description: 'The reason for the kick',
        required: true,
        type: 3,
      }],

To get the type use this https://discord.com/developers/docs/interactions/application-commands#:~:text=by%20the%20application.-,Application%20Command%20Option%20Type,-NAME