Skip to content

Commit

Permalink
patch: error reply embed field now shows correct subcommand and subco…
Browse files Browse the repository at this point in the history
…mmand group keys

Just had to update this with new support for these!
  • Loading branch information
Pkmmte committed May 15, 2023
1 parent 9b5923f commit 8fe87c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-deers-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roboplay/robo.js': patch
---

patch: error reply embed field now shows correct subcommand and subcommand group keys
25 changes: 23 additions & 2 deletions packages/robo/src/core/debug.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { hasProperties } from '../cli/utils/utils.js'
import fs from 'node:fs/promises'
import {
ActionRowBuilder,
Expand Down Expand Up @@ -50,7 +51,11 @@ export async function printErrorResponse(error: unknown, interaction: unknown, d
}

// Return if interaction is not a Discord command interaction or a message directed at the bot
if (!(interaction instanceof CommandInteraction) && !(interaction instanceof Message) && !(interaction instanceof ButtonInteraction)) {
if (
!(interaction instanceof CommandInteraction) &&
!(interaction instanceof Message) &&
!(interaction instanceof ButtonInteraction)
) {
return
}

Expand Down Expand Up @@ -185,9 +190,25 @@ async function formatError(options: FormatErrorOptions): Promise<FormatErrorResu

// Include additional details available
if (interaction instanceof CommandInteraction) {
const commandKeys = [interaction.commandName]
if (hasProperties<{ getSubcommandGroup: () => string }>(interaction.options, ['getSubcommandGroup'])) {
try {
commandKeys.push(interaction.options.getSubcommandGroup())
} catch {
// Ignore
}
}
if (hasProperties<{ getSubcommand: () => string }>(interaction.options, ['getSubcommand'])) {
try {
commandKeys.push(interaction.options.getSubcommand())
} catch {
// Ignore
}
}

fields.push({
name: 'Command',
value: '`/' + interaction.commandName + '`'
value: '`/' + commandKeys.filter(Boolean).join(' ') + '`'
})
}
if (details) {
Expand Down

0 comments on commit 8fe87c3

Please sign in to comment.