Add RequiredInput to example modal (#2348) - Misha-133
This commit is contained in:
@@ -13,6 +13,8 @@ public class FoodModal : IModal
|
|||||||
public string Food { get; set; }
|
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??")]
|
[InputLabel("Why??")]
|
||||||
[ModalTextInput("food_reason", TextInputStyle.Paragraph, "Kuz it's tasty", maxLength: 500)]
|
[ModalTextInput("food_reason", TextInputStyle.Paragraph, "Kuz it's tasty", maxLength: 500)]
|
||||||
public string Reason { get; set; }
|
public string Reason { get; set; }
|
||||||
@@ -22,10 +24,15 @@ public class FoodModal : IModal
|
|||||||
[ModalInteraction("food_menu")]
|
[ModalInteraction("food_menu")]
|
||||||
public async Task ModalResponse(FoodModal modal)
|
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.
|
// Build the message to send.
|
||||||
string message = "hey @everyone, I just learned " +
|
string message = "hey @everyone, I just learned " +
|
||||||
$"{Context.User.Mention}'s favorite food is " +
|
$"{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.
|
// Specify the AllowedMentions so we don't actually ping everyone.
|
||||||
AllowedMentions mentions = new();
|
AllowedMentions mentions = new();
|
||||||
|
|||||||
Reference in New Issue
Block a user