Skip to content

Commit 522c316

Browse files
committed
feat(commands): better errors for /track
closes #32
1 parent 411c998 commit 522c316

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/commands.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,17 @@ const commands: Record<string, Command> = {
343343
return;
344344
}
345345

346-
// Check if the channel is already being tracked in the guild
347-
if (
346+
const trackedChannels =
348347
await checkIfGuildIsTrackingChannelAlready(
349348
platformUserId,
350349
guildId,
351-
)
352-
) {
350+
);
351+
352+
// Check if the channel is already being tracked in the guild
353+
if (trackedChannels.length) {
353354
await interaction.reply({
354355
flags: MessageFlags.Ephemeral,
355-
content: "This channel is already being tracked!",
356+
content: `This channel is already being tracked in ${trackedChannels.map((channel, index) => `${index > 0 && index === trackedChannels.length - 1 ? "and " : ""}<#${channel.guild_channel_id}>`).join(", ")}!`,
356357
});
357358

358359
return;

src/utils/database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { dbDiscordTable, dbYouTube } from "../types/database";
1+
import type { dbDiscordTable } from "../types/database";
22

33
import { Pool } from "pg";
44

5-
import { dbCredentials, env } from "../config";
5+
import { dbCredentials } from "../config";
66

77
// import path from "path";
88
// import { Database } from "bun:sqlite";
@@ -30,14 +30,14 @@ export const pool: Pool = new Pool({
3030
export async function checkIfGuildIsTrackingChannelAlready(
3131
channelId: string,
3232
guild_id: string,
33-
) {
33+
): Promise<dbDiscordTable[]> {
3434
const query = `SELECT * FROM discord WHERE platform_user_id = ? AND guild_id = ?`;
3535

3636
try {
3737
const statement = db.prepare(query);
3838
const result = statement.all(channelId, guild_id);
3939

40-
return result.length > 0;
40+
return result;
4141
} catch (err) {
4242
console.error(
4343
"Error checking if guild is tracking channel already:",

0 commit comments

Comments
 (0)