Browse Source

Create Complex Params Docs (#2160)

* create complex params docs

* Update docs/guides/int_framework/intro.md

Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
tags/3.4.0
Cenk Ergen GitHub 3 years ago
parent
commit
5522bc443d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions
  1. +15
    -0
      docs/guides/int_framework/intro.md
  2. +37
    -0
      docs/guides/int_framework/samples/intro/complexparams.cs

+ 15
- 0
docs/guides/int_framework/intro.md View File

@@ -143,6 +143,21 @@ In this case, user can only input Stage Channels and Text Channels to this param


You can specify the permitted max/min value for a number type parameter using the [MaxValueAttribute] and [MinValueAttribute]. You can specify the permitted max/min value for a number type parameter using the [MaxValueAttribute] and [MinValueAttribute].


#### Complex Parameters

This allows users to create slash command options using an object's constructor allowing complex objects to be created which cannot be infered from only one input value.
Constructor methods support every attribute type that can be used with the regular slash commands ([Autocomplete], [Summary] etc. ).
Preferred constructor of a Type can be specified either by passing a `Type[]` to the `[ComplexParameterAttribute]` or tagging a type constructor with the `[ComplexParameterCtorAttribute]`. If nothing is specified, the InteractionService defaults to the only public constructor of the type.
TypeConverter pattern is used to parse the constructor methods objects.

[!code-csharp[Complex Parameter](samples/intro/usercommand.cs)]

Interaction service complex parameter constructors are prioritized in the following order:

1. Constructor matching the signature provided in the `[ComplexParameter(Type[])]` overload.
2. Constuctor tagged with `[ComplexParameterCtor]`.
3. Type's only public constuctor.

## User Commands ## User Commands


A valid User Command must have the following structure: A valid User Command must have the following structure:


+ 37
- 0
docs/guides/int_framework/samples/intro/complexparams.cs View File

@@ -0,0 +1,37 @@
public class Vector3
{
public int X {get;}
public int Y {get;}
public int Z {get;}

public Vector3()
{
X = 0;
Y = 0;
Z = 0;
}

[ComplexParameterCtor]
public Vector3(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
}

// Both of the commands below are displayed to the users identically.

// With complex parameter
[SlashCommand("create-vector", "Create a 3D vector.")]
public async Task CreateVector([ComplexParameter]Vector3 vector3)
{
...
}

// Without complex parameter
[SlashCommand("create-vector", "Create a 3D vector.")]
public async Task CreateVector(int x, int y, int z)
{
...
}

Loading…
Cancel
Save