Skip to content

Commit

Permalink
Merge pull request #234 from harmonyland/option-channel-types
Browse files Browse the repository at this point in the history
feat(interactions/application_commands): add support for channelTypes…
  • Loading branch information
Helloyunho authored Oct 1, 2021
2 parents 71a8cd0 + 97c532c commit c7b5a72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/interactions/applicationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ApplicationCommandPermissionPayload,
ApplicationCommandPermissionType
} from '../types/applicationCommand.ts'
import { ChannelTypes } from '../types/channel.ts'
import { Collection } from '../utils/collection.ts'
import type {
InteractionsClient,
Expand Down Expand Up @@ -259,9 +260,16 @@ export function transformApplicationCommandOption(
if (typeof data.type === 'string') {
data.type = ApplicationCommandOptionType[data.type.toUpperCase()]
}
if (typeof data.options === 'object' && Array.isArray(data.options)) {
if (Array.isArray(data.options)) {
data.options = data.options.map(transformApplicationCommandOption)
}
if (Array.isArray(data.channelTypes)) {
data.channel_types = data.channelTypes.map(
(e: ApplicationCommandOption['channelTypes']) =>
typeof e === 'string' ? ChannelTypes[e] : e
)
delete data.channel_types
}
return data
}

Expand Down
8 changes: 6 additions & 2 deletions src/types/applicationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ export interface ApplicationCommandOptionPayload
extends ApplicationCommandOptionBase<
ApplicationCommandOptionPayload,
ApplicationCommandOptionType
> {}
> {
channel_types?: ChannelTypes[]
}

export type { ApplicationCommandOptionPayload as SlashCommandOptionPayload }

export interface ApplicationCommandOption
extends ApplicationCommandOptionBase<
ApplicationCommandOption,
ApplicationCommandOptionType | keyof typeof ApplicationCommandOptionType
> {}
> {
channelTypes?: Array<ChannelTypes | keyof typeof ChannelTypes>
}

export type { ApplicationCommandOption as SlashCommandOption }

Expand Down

0 comments on commit c7b5a72

Please sign in to comment.