systemGene
systemGene

Reputation: 67

How do you add arguments for the event interactionCreate in discord.js V13

I recently switched from discord.js V12 to discord.js V13

How do you add arguments to slash commands?
Ex: /verify UsernameHere

I am trying to make a verify system as i am very interested on slash commands.
Any help is appreciated; Thank you!

Upvotes: 1

Views: 5107

Answers (1)

UltraX
UltraX

Reputation: 379

Slash commands have options where you can set them up with the following types:

SUB_COMMAND sets the option to be a subcommand
SUB_COMMAND_GROUP sets the option to be a subcommand group
STRING sets the option to require a string value
INTEGER sets the option to require an integer value
NUMBER sets the option to require a decimal (also known as a floating point) value
BOOLEAN sets the option to require a boolean value
USER sets the option to require a user or snowflake as value
CHANNEL sets the option to require a channel or snowflake as value
ROLE sets the option to require a role or snowflake as value
MENTIONABLE sets the option to require a user, role or snowflake as value

You can check them out in the guides option types

So now to reply to them you will need to parse the option where you can find a detailed explanation at guides-parsing-options

const string = interaction.options.getString('input');
const integer = interaction.options.getInteger('int');
const number = interaction.options.getNumber('num');
const boolean = interaction.options.getBoolean('choice');
const user = interaction.options.getUser('target');
const member = interaction.options.getMember('target');
const channel = interaction.options.getChannel('destination');
const role = interaction.options.getRole('muted');
const mentionable = interaction.options.getMentionable('mentionable');

console.log([string, integer, boolean, user, member, channel, role, mentionable]);

example of slash command:

const data = {
  name: "verify", // no uppercase, else you will get an error
  description: "Example description",
  options: [{
    name: "username", // no uppercase as well
    description: "example option description",
    type: "USER"
  }]
}

I hope you found this helpful! :)

Upvotes: 2

Related Questions