diff --git a/packages/discord.js/src/structures/BaseChannel.js b/packages/discord.js/src/structures/BaseChannel.js index ebb956828..92e770825 100644 --- a/packages/discord.js/src/structures/BaseChannel.js +++ b/packages/discord.js/src/structures/BaseChannel.js @@ -6,6 +6,7 @@ const { ChannelType, Routes } = require('discord-api-types/v10'); const Base = require('./Base'); const ChannelFlagsBitField = require('../util/ChannelFlagsBitField'); const { ThreadChannelTypes } = require('../util/Constants'); +const PermissionsBitField = require('../util/PermissionsBitField'); /** * Represents any channel on Discord. @@ -42,6 +43,31 @@ class BaseChannel extends Base { * @type {Snowflake} */ this.id = data.id; + + if ('permissions' in data) { + /** + * The computed permissions of the user who invoked the interaction in this channel, including overwrites. + * This is only present on channels received through an interaction's resolved data. + * + * @type {?Readonly} + */ + this.permissions = new PermissionsBitField(data.permissions).freeze(); + } else { + this.permissions ??= null; + } + + if ('app_permissions' in data) { + /** + * The computed permissions of the application in this channel, including overwrites. + * This is only present on channels received through an interaction's resolved data, and only when the + * application's bot user is in the guild. + * + * @type {?Readonly} + */ + this.appPermissions = new PermissionsBitField(data.app_permissions).freeze(); + } else { + this.appPermissions ??= null; + } } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 9f24cbae8..8be7ec02e 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1100,6 +1100,8 @@ export abstract class BaseChannel extends Base { public get createdTimestamp(): number | null; public id: Snowflake; public flags: Readonly | null; + public permissions: Readonly | null; + public appPermissions: Readonly | null; public get partial(): false; public type: ChannelType; public get url(): string; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index e8196d542..7aab67ad8 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -2225,6 +2225,10 @@ client.on('interactionCreate', async interaction => { interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]), ); expectType(interaction.options.getChannel('test', true, [ChannelType.GuildMedia])); + + const resolvedChannel = interaction.options.getChannel('test', true); + expectType | null>(resolvedChannel.permissions); + expectType | null>(resolvedChannel.appPermissions); } else { expectType(interaction); expectType>(interaction.reply({ fetchReply: true }));