Skip to content

Add support for returning ValueTask's in Slash Command methods. #321

@AraHaan

Description

@AraHaan

Description

I have a specific use case where I must have my slash command methods in my commands "module" to be async and part of making things async is to make it return ValueTask. Since the code throws InvalidDefinitionException it can special case ValueTask and run the command in Async. Also it is interesting that if one needs to return NetCord.Rest.InteractionMessageProperties in said ValueTask (just so they can mark some of the Flags on some of the responses as Ephemeral others with Flags not set, but with Embeds set in its place).

Just a few cases where doing so simply crashed my bot since the exception bubbles up to my minimal Program.cs.

What I use in the commands that makes me need to have it Async:

  • EFCore

Ironically returning only InteractionMessageProperties and having a copy of the custom async methods I added to my DbContext for the bot, and calling the non-async version of CreateDbContext from IDbContextFactory<T> works., however I would have expected the async version with it wrapped in ValueTask to also work since the rest of NetCord is async in nature.

The reason why I used EFCore's async methods when implementing my own async methods is so that way I could avoid some threading issues where it would have problems with the DbContext since it is not thread safe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions