Skip to content

fix(ClientPermissions): check app permissions when used with user apps#797

Merged
favna merged 3 commits intosapphiredev:mainfrom
yuansheng1549:fix/fix-client-permissions
Nov 4, 2024
Merged

fix(ClientPermissions): check app permissions when used with user apps#797
favna merged 3 commits intosapphiredev:mainfrom
yuansheng1549:fix/fix-client-permissions

Conversation

@yuansheng1549
Copy link
Copy Markdown
Contributor

interaction.channel will always be null when used with user-installable and since ClientPermissions always fetch the invoked interaction channel, it will throw an error causing "The application did not respond"

protected async fetchChannelFromInteraction(interaction: CommandInteraction): Promise<TextBasedChannel> {
const channel = (await interaction.client.channels.fetch(interaction.channelId, {
cache: false,
allowUnknownGuild: true
})) as TextBasedChannel;
return channel;
}

image

Comment thread src/preconditions/ClientPermissions.ts Outdated
Comment thread src/preconditions/ClientPermissions.ts Outdated
Co-authored-by: Aura <kyradiscord@gmail.com>
@yuansheng1549 yuansheng1549 changed the title fix(ClientPermissions): always return this.ok when channel is null fix(ClientPermissions): check app permissions when used with user apps Nov 3, 2024
if (interaction.channel) {
if (interaction.channel.isDMBased()) return this.dmChannelPermissions;

const channel = await this.fetchChannelFromInteraction(interaction);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fetch feels redundant now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better safe than sorry and it's gonna come out of the cache anyway if it's there.

@favna favna merged commit ebdf0f7 into sapphiredev:main Nov 4, 2024
@yuansheng1549 yuansheng1549 deleted the fix/fix-client-permissions branch November 5, 2024 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants