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)
- [BUG] Automod events not working HOT 2
- RoleCreateOptions#position doesn't always work HOT 2
- Make Interaction#editReply and Interaction#followUp await for Interaction#deferUpdate and Interaction#deferReply HOT 6
- User#avatarDecoration property is always null. HOT 4
- Scheduled Events missing "location" for entityType: external HOT 1
- throw error if user presence update fails, or add way to fetch current presence HOT 7
- [Bug]: Showing the pop-up of ENABLE AUTHENTICATION APP box even when back button is clicked. HOT 1
- Support installation_types for slash command builders
- ECONNRESET HOT 1
- Bot is joining the voice call and talking (see the green border), however I am unable to hear anything... HOT 1
- add after and before function to collection HOT 2
- unable to verify the first certificate HOT 6
- Embed description can be cut off when using too many emojis HOT 1
- Some link tags resolve as empty spans
- I've been told that a recent update to ESET antivirus software has been causing this issue for some people. Otherwise, this issue has nothing to do with discord.js, as it's caused by external factors out of our control. HOT 2
- RangeError: Invalid WebSocket frame: RSV1 must be clear HOT 5
- Send file from Buffer with utf-8 encoding issue on Discord channel view HOT 1
- Unstable user count measurement in client.shard.broadcastEval() HOT 2
- DiscordAPIError[10062]: Unknown interaction (AutoComplete)
- Discord API REST response body access HOT 1
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.