It is not possible to assign void to an implicitly typed variable. C# Discord.Net bot

77 Views Asked by At
private async Task HandleButtonInteraction(SocketInteraction interaction)
{
    if (interaction is SocketMessageComponent buttonInteraction)
    {
        if (buttonInteraction.Data.CustomId == "Поддержка")
        {
            var userWhoClicked = buttonInteraction.User;

            var mb = new ModalBuilder()
                .WithTitle("Поддержка")
                .WithCustomId("support_menu")
                .AddTextInput("Краткое объяснение тикета", "support_name", placeholder: "Например: меня обозвал FenixRUS")
                .AddTextInput("Описание тикета", "support_reason", TextInputStyle.Paragraph, "Распишите, что к чему");

            await interaction.RespondWithModalAsync(mb.Build());
        }
        else if (buttonInteraction.Data.CustomId == "Верификация")
        {
            var userWhoClicked = buttonInteraction.User;

            var verificationMb = new ModalBuilder()
                .WithTitle("Верификация")
                .WithCustomId("verification_menu")
                .AddTextInput("Ваш ник?", "verification_additional", TextInputStyle.Paragraph, "NeSHIZ...");

            var verificationResponse = await interaction.RespondWithModalAsync(verificationMb.Build());
            var verificationAdditional = verificationResponse.GetTextInput("verification_additional") as string;

            SaveVerificationToDatabase(userWhoClicked.Username, verificationAdditional);
        }

    }
}

I haven't tried to do anything because I don't have the knowledge and I haven't found a similar case on the Internet. Although I found articles parsing the error, but it didn't help.

This line is the problem

var verificationResponse = await interaction.RespondWithModalAsync(verificationMb.Build());
1

There are 1 best solutions below

0
possum On

SocketMessageComponent.RespondWithModalAsync indeed returns a Task without a value.

https://discordnet.dev/api/Discord.WebSocket.SocketMessageComponent.html

You're going to need another interaction clause like

public async Task OnInteractionReceived(SocketInteraction interaction)
{
    if (interaction is SocketModal modal)
    {
        var verificationAdditional = modal.Data.Components.FirstOrDefault(x => x.CustomId == "verification_additional")?.Value;

        // I'm leaving it open on how you'd like to get userWhoClicked
        SaveVerificationToDatabase(userWhoClicked.Username, verificationAdditional);
    }
}