Skip to content

v4: ComponentHandler should allow type-constructing handlers #402

@diamondburned

Description

@diamondburned

Currently, ComponentHandlers accept a ComponentData interface, and assertions must be done by the user. The user can make a mistake where an incorrect ID is used, causing a handler that expects one type to get an interaction of another type.

API proposal:

// Usage:
h.AddComponent("id", func(ctx context.Context, data ComponentData[*discord.ButtonInteraction]) {})

// Decls:
type ComponentData[T discord.ComponentInteraction] {...}
type ComponentHandler[T discord.ComponentInteraction] {...}
func (r *Router) AddComponent[T discord.ComponentInteraction](...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions