Skip to content
GitHub

findRouteConflicts

function in meocord/testing Since 4.0.0

findRouteConflicts(app: ControllerClass): RouteConflict[]

Finds component patterns that can match the same customId, which MeoCord otherwise only warns about at startup.

Use it in a test to keep the warning from reaching production: two patterns that trade a literal for a parameter in opposite places both take one id, and neither is more specific. Patterns are compared within a component type.

Parameters

NameTypeDescription
appControllerClass

The application class decorated with @MeoCord.

Returns

RouteConflict[]

Each pair of patterns that can match the same customId, with its component type.

Examples

TypeScript
import { expect } from 'vitest'

@Controller()
class CardController {
  @Command('card/{id}/open', CommandType.BUTTON)
  async open(interaction: ButtonInteraction) { await respond(interaction).send('Opened.') }
  @Command('card/new/{kind}', CommandType.BUTTON)
  async create(interaction: ButtonInteraction) { await respond(interaction).send('Created.') }
}
@MeoCord({ controllers: [CardController], clientOptions: { intents: [] } })
class App {}
expect(findRouteConflicts(App)).toHaveLength(1)