[SlashCommand("food", "Tell us about your favorite food.")]
public async Task Command()
=> await Context.Interaction.RespondWithModalAsync<FoodModal>("food_menu");
[ModalInteraction("food_menu")]
public async Task ModalResponce(FoodModal modal)
{
// Build the message to send.
string message = "hey @everyone, I just learned " +
$"{Context.User.Mention}'s favorite food is " +
$"{modal.Food} because {modal.Reason}.";
// Specify the AllowedMentions so we don't actually ping everyone.
AllowedMentions mentions = new();
mentions.AllowedTypes = AllowedMentionTypes.Users;
// Respond to the modal.
await RespondAsync(message, allowedMentions: mentions, ephemeral:true);
}
public class FoodModal : IModal
{
public string Title => "Fav Food";
// Strings with the ModalTextInput attribute will automatically
[InputLabel("What??")]
[ModalTextInput("food_name", placeholder:"Pizza", maxLength:20)]
public string Food { get; set; }
// Additional paremeters can be specified to further customize the input.
[InputLabel("Why??")]
[ModalTextInput("food_reason", TextInputStyle.Paragraph, "Kuz it's tasty", maxLength:500)]
public string Reason { get; set; }
}
How It Works
Without the interaction service
With the interaction service (sample from cenngo)
How It Looks