generated from sapphiredev/sapphire-template
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: changed no match errors to emit on a subcommand listener in…
…stead of the root MessageCommandError / ChatInputCommandError (#601) BREAKING CHANGE: If no subcommand matched the error was emitted to `MessageCommandError` or `ChatInputCommandError`. This was inconsistent with errors during runtime emitted to `MessageSubcommandError` and `ChatInputSubcommandError` respectively. Therefore these events are now emitted to the new events `PluginMessageSubcommandNoMatch` and `PluginChatInputSubcommandNoMatch` respectively. New built-in listeners for these events will log the infractions to the console at the error level. You can override these listeners to provide your functionality.
- Loading branch information
Showing
5 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/subcommands/src/listeners/PluginChatInputSubcommandNoMatch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Listener, type ChatInputCommand } from '@sapphire/framework'; | ||
import { SubcommandPluginEvents, type ChatInputSubcommandNoMatchContext } from '../lib/types/Events'; | ||
|
||
export class PluginListener extends Listener<typeof SubcommandPluginEvents.ChatInputSubcommandNoMatch> { | ||
public constructor(context: Listener.LoaderContext) { | ||
super(context, { event: SubcommandPluginEvents.ChatInputSubcommandNoMatch }); | ||
} | ||
|
||
public override run(_interaction: ChatInputCommand.Interaction, context: ChatInputSubcommandNoMatchContext) { | ||
this.container.logger.error(context.message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/subcommands/src/listeners/PluginMessageSubcommandNoMatch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Args, Listener } from '@sapphire/framework'; | ||
import type { Message } from 'discord.js'; | ||
import { SubcommandPluginEvents, type MessageSubcommandNoMatchContext } from '../lib/types/Events'; | ||
|
||
export class PluginListener extends Listener<typeof SubcommandPluginEvents.MessageSubcommandNoMatch> { | ||
public constructor(context: Listener.LoaderContext) { | ||
super(context, { event: SubcommandPluginEvents.MessageSubcommandNoMatch }); | ||
} | ||
|
||
public override run(_message: Message, _args: Args, context: MessageSubcommandNoMatchContext) { | ||
this.container.logger.error(context.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters