Comments (3)
Thats just a bitfield, whose behaviour we shouldnt change
Better to add methods like TextChannel#sendableFor
to allow more complex checks
from discord.js.
One thing I have noticed is an interaction's appPermissions
will change its bit field if timed out. Currently, non-interaction-based permission checks do not change their bitfield.
from discord.js.
Suggestion
This is one of the solutions which is a breaking change.
GuildChannel#permissionsFor()
Before:
discord.js/packages/discord.js/src/structures/GuildChannel.js
Lines 175 to 180 in a1a3a95
After:
permissionsFor(memberOrRole, { checkAdmin = true, checkTimeout = true } = {}) {
const member = this.guild.members.resolve(memberOrRole);
if (member) return this.memberPermissions(member, { checkAdmin, checkTimeout });
const role = this.guild.roles.resolve(memberOrRole);
return role && this.rolePermissions(role, checkAdmin);
}
GuildChannel#memberPermissions()
Private Method
Before:
discord.js/packages/discord.js/src/structures/GuildChannel.js
Lines 216 to 238 in a1a3a95
After:
memberPermissions(member, { checkAdmin, checkTimeout }) {
if (checkAdmin && member.id === this.guild.ownerId) {
return new PermissionsBitField(PermissionsBitField.All).freeze();
}
const roles = member.roles.cache;
const rolePermissions = new PermissionsBitField(roles.map(role => role.permissions));
if (checkAdmin && rolePermissions.has(PermissionFlagsBits.Administrator)) {
return new PermissionsBitField(PermissionsBitField.All).freeze();
}
const overwrites = this.overwritesFor(member, true, roles);
const channelPermissions = rolePermissions
.remove(overwrites.everyone?.deny ?? PermissionsBitField.DefaultBit)
.add(overwrites.everyone?.allow ?? PermissionsBitField.DefaultBit)
.remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny) : PermissionsBitField.DefaultBit)
.add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow) : PermissionsBitField.DefaultBit)
.remove(overwrites.member?.deny ?? PermissionsBitField.DefaultBit)
.add(overwrites.member?.allow ?? PermissionsBitField.DefaultBit);
if (
!checkTimeout
|| member.id === this.guild.ownerId
|| channelPermissions.has(PermissionFlagsBits.Administrator)
|| !member.isCommunicationDisabled()
) {
return channelPermissions.freeze();
}
return new PermissionsBitField(
channelPermissions.has(PermissionFlagsBits.ViewChannel) ? PermissionFlagsBits.ViewChannel : PermissionsBitField.DefaultBit |
channelPermissions.has(PermissionFlagsBits.ReadMessageHistory) ? PermissionFlagsBits.ReadMessageHistory : PermissionsBitField.DefaultBit
).freeze();
}
from discord.js.
Related Issues (20)
- Discord API REST response body access HOT 1
- `setDMPermission` and `setDefaultMemberPermissions` do not exist on type 'SlashCommandOptionsOnlyBuilder' HOT 1
- Slash command builder type incompatibility HOT 4
- Poll not being created on slash command interaction HOT 4
- `ActionRowBuilder<T>` does not enforce the type of the components to be `T` HOT 1
- Include which users answered what on the finished polls on the payload HOT 2
- Cannot use module due to version upgrading HOT 2
- Ban Appeal
- addChoices in RoleSelectMenuBuilder or in addRoleOption (SlashCommandRoleOption) HOT 1
- Redis ReplyError when pulling with xreadgroup on empty subscribed events HOT 2
- Add `reason` to follow announcement channel endpoint
- Have event handler callbacks support both async/sync methods HOT 3
- No definition found for the 'commands' property HOT 1
- Ambiguous event names: LinkTags and Anchors
- Only messages are allowed to create polls HOT 1
- Merged interfaces from package overview 404.
- Inaccurate typings for GuildMember#partial
- `Message#fetchReference()` returns a non-message on certain message types
- @discordjs/voice not working with Bun HOT 1
- fix MessagePayload.js to send voice message
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discord.js.