diamondburned / arikawa

A Golang library and framework for the Discord API.
ISC License
469 stars 55 forks source link

v4: ComponentHandler should allow type-constructing handlers #402

Open diamondburned opened 1 year ago

diamondburned commented 1 year ago

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](...)