Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash commands are not accepting arguments #174

Open
4Lajf opened this issue Oct 5, 2021 · 2 comments
Open

Slash commands are not accepting arguments #174

4Lajf opened this issue Oct 5, 2021 · 2 comments

Comments

@4Lajf
Copy link

4Lajf commented Oct 5, 2021

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
Copy link

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
Copy link

GamerBossHarmon commented Dec 24, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants