Fix channel resolution

This commit is contained in:
Tarrgon
2025-07-23 20:10:13 -04:00
parent 023c4037e6
commit ef48c1d8d2
+6 -7
View File
@@ -1,8 +1,9 @@
import { APIEmbedField, Channel, EmbedBuilder, Guild, GuildTextBasedChannel, messageLink, TextBasedChannel } from 'discord.js'; import { APIEmbedField, Channel, EmbedBuilder, Guild, GuildBasedChannel, GuildTextBasedChannel, messageLink, TextBasedChannel } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { Message } from '../events'; import { Message } from '../events';
import { deserializeMessagePart, getModifiedAttachments, getModifiedStickers } from './message-utils'; import { deserializeMessagePart, getModifiedAttachments, getModifiedStickers } from './message-utils';
import { LoggedMessage } from '../types'; import { LoggedMessage } from '../types';
import { channelIsInStaffCategory } from './channel-utils';
type CustomEventLogData = { type CustomEventLogData = {
title: string title: string
@@ -13,7 +14,7 @@ type CustomEventLogData = {
} }
export async function logEdit(loggedMessage: LoggedMessage, newMessage: Message<true>) { export async function logEdit(loggedMessage: LoggedMessage, newMessage: Message<true>) {
const channel = await getEventLogChannel(newMessage.guild, newMessage.channel.parentId); const channel = await getEventLogChannel(newMessage.guild, newMessage.channel);
if (!channel) return; if (!channel) return;
@@ -31,7 +32,7 @@ export async function logEdit(loggedMessage: LoggedMessage, newMessage: Message<
} }
export async function logDeletion(loggedMessage: LoggedMessage, deletedMessage: Message<true>) { export async function logDeletion(loggedMessage: LoggedMessage, deletedMessage: Message<true>) {
const channel = await getEventLogChannel(deletedMessage.guild, deletedMessage.channel.parentId); const channel = await getEventLogChannel(deletedMessage.guild, deletedMessage.channel);
if (!channel) return; if (!channel) return;
@@ -63,14 +64,12 @@ export async function logCustomEvent(guild: Guild, data: CustomEventLogData) {
channel.send({ embeds: [embed] }); channel.send({ embeds: [embed] });
} }
async function getEventLogChannel(guild: Guild, parentId: string | null = null): Promise<GuildTextBasedChannel | null> { async function getEventLogChannel(guild: Guild, channel: GuildBasedChannel | null): Promise<GuildTextBasedChannel | null> {
const settings = await Database.getGuildSettings(guild.id); const settings = await Database.getGuildSettings(guild.id);
if (!settings) return null; if (!settings) return null;
const staffCategories = await Database.getGuildArraySetting('staff_categories', guild.id); if (channel && await channelIsInStaffCategory(channel)) {
if (parentId != null && staffCategories.includes(parentId)) {
if (!settings.event_logs_channel_id) return null; if (!settings.event_logs_channel_id) return null;
const channel = await guild.channels.fetch(settings.event_logs_channel_id); const channel = await guild.channels.fetch(settings.event_logs_channel_id);