diff --git a/src/commands/mod/restriction/restrictLogs.ts b/src/commands/mod/restriction/restrictLogs.ts index 8fb0f11..add7099 100644 --- a/src/commands/mod/restriction/restrictLogs.ts +++ b/src/commands/mod/restriction/restrictLogs.ts @@ -75,10 +75,9 @@ export class RestrictLogsCommand extends Command { userId = user.id; } - let staffChannel = false; - if (channel.type === ChannelType.GuildText) { + const staffChannel = checkStaff(channel); + if (staffChannel) { channel = channel as TextChannel; - staffChannel = checkStaff(channel); if (userId === null) { let topic: string[]; diff --git a/src/commands/mod/sus.ts b/src/commands/mod/sus.ts index 0968c05..633965a 100644 --- a/src/commands/mod/sus.ts +++ b/src/commands/mod/sus.ts @@ -20,14 +20,13 @@ import { RegisterBehavior, Args } from '@sapphire/framework'; import { Subcommand } from '@sapphire/plugin-subcommands'; import { - ChannelType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, } from 'discord.js'; -import type { Message, GuildMember, TextChannel } from 'discord.js'; +import type { Message, GuildMember } from 'discord.js'; import { isMessageInstance } from '@sapphire/discord.js-utilities'; import { addExistingUser } from '#utils/database/dbExistingUser'; import { @@ -43,7 +42,10 @@ import IDs from '#utils/ids'; // TODO add a check when they join the server to give the user the sus role again export class SusCommand extends Subcommand { - public constructor(context: Subcommand.LoaderContext, options: Subcommand.Options) { + public constructor( + context: Subcommand.LoaderContext, + options: Subcommand.Options, + ) { super(context, { ...options, name: 'sus', @@ -201,14 +203,7 @@ export class SusCommand extends Subcommand { return; } - let staffChannel = false; - let { channel } = interaction; - if (channel !== null) { - if (channel.type === ChannelType.GuildText) { - channel = channel as TextChannel; - staffChannel = checkStaff(channel); - } - } + const staffChannel = checkStaff(interaction.channel); // Gets the sus notes from the database const notes = await findNotes(user.id, true); diff --git a/src/utils/checker.ts b/src/utils/checker.ts index 4717294..78e1301 100644 --- a/src/utils/checker.ts +++ b/src/utils/checker.ts @@ -17,8 +17,9 @@ along with this program. If not, see . */ -import type { TextChannel } from 'discord.js'; +import type { TextBasedChannel } from 'discord.js'; import IDs from '#utils/ids'; +import { ChannelType } from 'discord.js'; /** * Checks if the channel is in the staff category. @@ -26,7 +27,15 @@ import IDs from '#utils/ids'; * @returns {boolean} true if is in staff channel */ -export function checkStaff(channel: TextChannel) { +export function checkStaff(channel: TextBasedChannel | null) { + if (channel === null) { + return false; + } + + if (channel.type !== ChannelType.GuildText) { + return false; + } + if (channel.parent === null) { return false; }