Skip to content

Commit

Permalink
fix: fixed the type cast
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Mar 9, 2023
1 parent b388b61 commit de3d380
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/preconditions/ClientPermissions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { isNullish } from '@sapphire/utilities';
import {
BaseGuildTextChannel,
BaseInteraction,
ChatInputCommandInteraction,
ContextMenuCommandInteraction,
PermissionFlagsBits,
PermissionsBitField,
PermissionsString,
type BaseGuildTextChannel,
TextBasedChannel,
type Message
} from 'discord.js';
import { Identifiers } from '../lib/errors/Identifiers';
Expand All @@ -33,7 +34,7 @@ export class CorePrecondition extends AllFlowsPrecondition {

public async messageRun(message: Message, _: Command, context: PermissionPreconditionContext): AllFlowsPrecondition.AsyncResult {
const required = context.permissions ?? new PermissionsBitField();
const channel = message.channel as BaseGuildTextChannel;
const { channel } = message;

if (!message.client.id) {
return this.error({
Expand All @@ -54,7 +55,7 @@ export class CorePrecondition extends AllFlowsPrecondition {
): AllFlowsPrecondition.AsyncResult {
const required = context.permissions ?? new PermissionsBitField();

const channel = (await this.fetchChannelFromInteraction(interaction)) as BaseGuildTextChannel;
const channel = await this.fetchChannelFromInteraction(interaction);

const permissions = await this.getPermissionsForChannel(channel, interaction);

Expand All @@ -68,17 +69,17 @@ export class CorePrecondition extends AllFlowsPrecondition {
): AllFlowsPrecondition.AsyncResult {
const required = context.permissions ?? new PermissionsBitField();

const channel = (await this.fetchChannelFromInteraction(interaction)) as BaseGuildTextChannel;
const channel = await this.fetchChannelFromInteraction(interaction);

const permissions = await this.getPermissionsForChannel(channel, interaction);

return this.sharedRun(required, permissions, 'context menu');
}

private async getPermissionsForChannel(channel: BaseGuildTextChannel, messageOrInteraction: Message | BaseInteraction) {
private async getPermissionsForChannel(channel: TextBasedChannel, messageOrInteraction: Message | BaseInteraction) {
let permissions: PermissionsBitField | null = this.dmChannelPermissions;

if (messageOrInteraction.inGuild()) {
if (messageOrInteraction.inGuild() && channel instanceof BaseGuildTextChannel) {

This comment has been minimized.

Copy link
@vladfrangu

vladfrangu Mar 9, 2023

Member

Can't you mix this with isText()?

if (!isNullish(messageOrInteraction.applicationId)) {
permissions = channel.permissionsFor(messageOrInteraction.applicationId);
}
Expand Down

0 comments on commit de3d380

Please sign in to comment.