mirror of
https://github.com/discordjs/discord.js.git
synced 2026-07-21 21:52:57 +00:00
feat(BaseChannel): add permissions and appPermissions (#11577)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,7 @@ const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
const { ChannelType, Routes } = require('discord-api-types/v10');
|
||||
const { ChannelFlagsBitField } = require('../util/ChannelFlagsBitField.js');
|
||||
const { ThreadChannelTypes } = require('../util/Constants.js');
|
||||
const { PermissionsBitField } = require('../util/PermissionsBitField.js');
|
||||
const { Base } = require('./Base.js');
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,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.
|
||||
* <info>This is only present on channels received through an interaction's resolved data.</info>
|
||||
*
|
||||
* @type {?Readonly<PermissionsBitField>}
|
||||
*/
|
||||
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.
|
||||
* <info>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.</info>
|
||||
*
|
||||
* @type {?Readonly<PermissionsBitField>}
|
||||
*/
|
||||
this.appPermissions = new PermissionsBitField(data.app_permissions).freeze();
|
||||
} else {
|
||||
this.appPermissions ??= null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
@@ -900,6 +900,8 @@ export abstract class BaseChannel extends Base {
|
||||
public get createdTimestamp(): number | null;
|
||||
public id: Snowflake;
|
||||
public flags: Readonly<ChannelFlagsBitField> | null;
|
||||
public permissions: Readonly<PermissionsBitField> | null;
|
||||
public appPermissions: Readonly<PermissionsBitField> | null;
|
||||
public get partial(): false;
|
||||
public type: ChannelType;
|
||||
public get url(): string;
|
||||
|
||||
@@ -2270,6 +2270,10 @@ client.on('interactionCreate', async interaction => {
|
||||
interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]),
|
||||
);
|
||||
expectType<MediaChannel>(interaction.options.getChannel('test', true, [ChannelType.GuildMedia]));
|
||||
|
||||
const resolvedChannel = interaction.options.getChannel('test', true);
|
||||
expectType<Readonly<PermissionsBitField> | null>(resolvedChannel.permissions);
|
||||
expectType<Readonly<PermissionsBitField> | null>(resolvedChannel.appPermissions);
|
||||
} else {
|
||||
expectType<ChatInputCommandInteraction>(interaction);
|
||||
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ withResponse: true }));
|
||||
|
||||
Reference in New Issue
Block a user