-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve message permission checks
- Loading branch information
1 parent
3debfb9
commit 0e88cd3
Showing
5 changed files
with
32 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as changelog } from './changelog.json' assert { type: 'json' }; | ||
export * from './fetchTags.js'; | ||
export * from './files.js'; | ||
export * from './sendable.js'; | ||
export * from './types.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type GuildTextBasedChannel, PermissionFlagsBits } from 'discord.js'; | ||
|
||
export async function isSendable(channel: GuildTextBasedChannel) { | ||
if (channel.isThread()) { | ||
return channel.sendable; | ||
} | ||
|
||
const permissions = channel.permissionsFor(channel.client.user); | ||
|
||
if (!permissions || !channel.viewable) { | ||
return false; | ||
} | ||
|
||
if (permissions.has(PermissionFlagsBits.Administrator, false)) { | ||
return true; | ||
} | ||
|
||
const clientMember = await channel.guild.members.fetchMe(); | ||
return permissions.has(PermissionFlagsBits.SendMessages, false) && !clientMember.isCommunicationDisabled(); | ||
} |