Browse Source

Add RequiredInput to example modal (#2348) - Misha-133

tags/3.8.0
Misha133 GitHub 2 years ago
parent
commit
ee6e0adf7c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      docs/guides/int_framework/samples/intro/modal.cs

+ 9
- 2
docs/guides/int_framework/samples/intro/modal.cs View File

@@ -12,7 +12,9 @@ public class FoodModal : IModal
[ModalTextInput("food_name", placeholder: "Pizza", maxLength: 20)]
public string Food { get; set; }

// Additional paremeters can be specified to further customize the input.
// Additional paremeters can be specified to further customize the input.
// Parameters can be optional
[RequiredInput(false)]
[InputLabel("Why??")]
[ModalTextInput("food_reason", TextInputStyle.Paragraph, "Kuz it's tasty", maxLength: 500)]
public string Reason { get; set; }
@@ -22,10 +24,15 @@ public class FoodModal : IModal
[ModalInteraction("food_menu")]
public async Task ModalResponse(FoodModal modal)
{
// Check if "Why??" field is populated
string reason = string.IsNullOrWhiteSpace(modal.Reason)
? "."
: $" because {modal.Reason}";

// Build the message to send.
string message = "hey @everyone, I just learned " +
$"{Context.User.Mention}'s favorite food is " +
$"{modal.Food} because {modal.Reason}.";
$"{modal.Food}{reason}";

// Specify the AllowedMentions so we don't actually ping everyone.
AllowedMentions mentions = new();


Loading…
Cancel
Save