Skip to content

Commit 746f238

Browse files
committed
chore: type interaction handler responses
1 parent 35309db commit 746f238

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

src/lib/discord/Command.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type {
33
APIApplicationCommand,
44
RESTPostAPIApplicationCommandsJSONBody,
55
} from 'discord-api-types/v9'
6-
import type { CommandInteraction } from 'discord.js'
7-
import { DiscordCommandOption } from './CommandOption'
6+
import type { CommandInteraction, InteractionReplyOptions } from 'discord.js'
7+
import type { DiscordCommandOption } from './CommandOption'
88

99
export interface IDiscordCommandConfig {
1010
name: string
@@ -16,7 +16,11 @@ export interface IDiscordCommandConfig {
1616

1717
export type DiscordCommandHandler = (
1818
interaction: CommandInteraction
19-
) => string | undefined | Promise<string | undefined>
19+
) =>
20+
| string
21+
| undefined
22+
| InteractionReplyOptions
23+
| Promise<string | undefined | InteractionReplyOptions>
2024

2125
export type CreateDiscordCommandInput = IDiscordCommandConfig & {
2226
handler: DiscordCommandHandler

src/lib/discord/commands/contribute.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCommand, createOption } from '$discord'
2-
import type { CommandInteraction } from 'discord.js'
2+
import type { CommandInteraction, InteractionReplyOptions } from 'discord.js'
33

44
const repository = createOption({
55
name: 'repository',
@@ -33,7 +33,9 @@ const command = createCommand({
3333
name: 'contribute',
3434
description: 'Learn how to contribute to an Amplify project',
3535
options: [repository],
36-
handler: (interaction: CommandInteraction) => {
36+
handler: (
37+
interaction: CommandInteraction
38+
): InteractionReplyOptions | string => {
3739
const [{ value: repository }] = interaction.options.data
3840
const lines = [
3941
'Thanks for your interest in contributing! To learn how to get started visit the contributing guide:',

src/lib/discord/commands/github.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCommand, createOption } from '$discord'
2-
import type { CommandInteraction } from 'discord.js'
2+
import type { CommandInteraction, InteractionReplyOptions } from 'discord.js'
33

44
const repository = createOption({
55
name: 'repository',
@@ -30,7 +30,9 @@ const command = createCommand({
3030
name: 'github',
3131
description: 'Gives link to GitHub repository',
3232
options: [repository],
33-
handler: (interaction: CommandInteraction) => {
33+
handler: (
34+
interaction: CommandInteraction
35+
): InteractionReplyOptions | string => {
3436
const [{ value: repository }] = interaction.options.data
3537
return getRepositoryUrl(repository as string)
3638
},

src/lib/discord/commands/giverole.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createCommand } from '$discord'
2-
import type { Role, User } from 'discord.js'
2+
import type { Role, User, InteractionReplyOptions } from 'discord.js'
33

4-
async function handler(interaction) {
4+
async function handler(interaction): Promise<InteractionReplyOptions | string> {
55
const { member: caller, guild } = interaction
66
const { role, user } = interaction.options.data.reduce(
77
(acc, current, index, source) => {

src/lib/discord/commands/thread.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { MessageEmbed } from 'discord.js'
22
import { createCommand, createOption } from '$discord'
3-
import type { ThreadChannel } from 'discord.js'
3+
import type { InteractionReplyOptions, ThreadChannel } from 'discord.js'
44
import { prisma } from '$lib/db'
55

66
export const PREFIXES = {
77
solved: '✅ - ',
88
open: '﹖ - ',
99
}
1010

11-
async function handler(interaction) {
11+
async function handler(interaction): Promise<InteractionReplyOptions | string> {
1212
const channel = interaction.channel as ThreadChannel
1313
const messages = await channel.messages.fetch()
1414
const record = await prisma.question.findUnique({

0 commit comments

Comments
 (0)