Skip to content

Commit

Permalink
feat: support media channels more
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Aug 13, 2023
1 parent dbbb702 commit 01ddaa9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const allowedChannelTypes = [
ChannelType.PrivateThread,
ChannelType.GuildStageVoice,
ChannelType.GuildForum,
// @ts-expect-error: discord-api-types.
ChannelType.GuildMedia,
] as const;

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/discord.js/src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

const { lazy } = require('@discordjs/util');
const { ChannelType, PermissionFlagsBits, Routes, ChannelFlags } = require('discord-api-types/v10');
const { BaseChannel } = require('./BaseChannel');
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
const GuildMessageManager = require('../managers/GuildMessageManager');
Expand Down Expand Up @@ -312,7 +314,7 @@ class ThreadChannel extends BaseChannel {
*/
// eslint-disable-next-line require-await
async fetchStarterMessage(options) {
const channel = this.parent?.type === ChannelType.GuildForum ? this : this.parent;
const channel = this.parent instanceof getThreadOnlyChannel() ? this : this.parent;
return channel?.messages.fetch({ message: this.id, ...options }) ?? null;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/discord.js/src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function makePlainError(err) {
};
}

const TextSortableGroupTypes = [ChannelType.GuildText, ChannelType.GuildAnnouncement, ChannelType.GuildForum];
// TODO: ChannelType.GuildMedia
const TextSortableGroupTypes = [ChannelType.GuildText, ChannelType.GuildAnnouncement, ChannelType.GuildForum, 16];
const VoiceSortableGroupTypes = [ChannelType.GuildVoice, ChannelType.GuildStageVoice];
const CategorySortableGroupTypes = [ChannelType.GuildCategory];

Expand All @@ -181,6 +182,8 @@ function getSortableGroupTypes(type) {
case ChannelType.GuildText:
case ChannelType.GuildAnnouncement:
case ChannelType.GuildForum:
case 16:
// TODO: ChannelType.GuildMedia
return TextSortableGroupTypes;
case ChannelType.GuildVoice:
case ChannelType.GuildStageVoice:
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ export interface MappedChannelCategoryTypes {
[ChannelType.GuildText]: TextChannel;
[ChannelType.GuildStageVoice]: StageChannel;
[ChannelType.GuildForum]: ForumChannel;
// @ts-expect-error discord-api-types.
[ChannelType.GuildMedia]: MediaChannel;
}

export type CategoryChannelType = Exclude<
Expand Down
7 changes: 7 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ import {
ChatInputApplicationCommandData,
ApplicationCommandPermissionsManager,
GuildOnboarding,
MediaChannel,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -1523,6 +1524,8 @@ declare const guildChannelManager: GuildChannelManager;
expectType<Promise<NewsChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildAnnouncement }));
expectType<Promise<StageChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildStageVoice }));
expectType<Promise<ForumChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildForum }));
// @ts-expect-error discord-api-types.
expectType<Promise<MediaChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildMedia }));

expectType<Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>>(guildChannelManager.fetch());
expectType<Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>>(
Expand Down Expand Up @@ -1905,6 +1908,10 @@ client.on('interactionCreate', async interaction => {
expectType<ForumChannel | VoiceChannel | null>(
interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]),
);
expectType<MediaChannel>(
// @ts-expect-error discord-api-types.
interaction.options.getChannel('test', true, [ChannelType.MediaChannel]),
);
} else {
// @ts-expect-error
consumeCachedCommand(interaction);
Expand Down

0 comments on commit 01ddaa9

Please sign in to comment.