#Checking permissions fail

51 messages · Page 1 of 1 (latest)

vocal moth
#

So lately i've noticed checking permissions just fails and breaks code . I really want to keep this in my code to prevent unneeded api calls

        if (!role.editable) {
            throw new Error("Not enough permissions to manage default role.");
        } else {
            return member.roles.add(role);
        }

and

   if (!interaction.channel.permissionsFor(interaction.guild.me).has(Permissions.FLAGS.MANAGE_MESSAGES)) {
        return interaction.editReply({ content: xyz })
    }

seem to either return a nullpointer or falsepositive. Any reason? I do try to fetch

    if (!interaction.guild) await InteractionController.interaction.guild.fetch();
    if (!interaction.member) await InteractionController.interaction.member.fetch();
    if (!interaction.channel) await InteractionController.interaction.channel.fetch();
magic phoenixBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

opal temple
#

fails and breaks code
fails and breaks how

vocal moth
#

this is for !role.editable

long basalt
vocal moth
# long basalt show full error stack
shard-0  |     at Role.get editable [as editable] (/usr/src/bot/node_modules/discord.js/src/structures/Role.js:209:23)
shard-0  |     at GuildController.addRoleToMember (/usr/src/bot/src/controllers/GuildController.js:328:19)
shard-0  |     at GuildController.AddRoleToMembers (/usr/src/bot/src/controllers/GuildController.js:340:24)
shard-0  |     at Object.exports.interaction (/usr/src/bot/src/commands/sync.js:39:43)
shard-0  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
long basalt
vocal moth
#

await guildController.AddRoleToMembers(members, role, interaction);

long basalt
#

or 43 idk

vocal moth
#

it just what call the if (!role.editable) { in the end...

long basalt
#

could you show the addRoleToMember function?

vocal moth
#
        if (!role.editable) {
            throw new Error("Not enough permissions to manage default role.");
        } else {
            return member.roles.add(role);
        }
    }```
long basalt
#

show sync.js file

#

the error originates from there

vocal moth
#

the error originates from if (!role.editable) { like i said

long basalt
#

are you providing a proper role?

vocal moth
#

i tried logging it and it shows a normal role

long basalt
#

does it have a editable: Boolean property?

vocal moth
#

it doesnt

opal temple
#

it won't cause that's a getter

vocal moth
#

ye thats right

#

it even has permission permissions: Permissions { bitfield: 6479466049n },

#

so i dont get why the editable doesnt work

opal temple
#

what's your version again?

vocal moth
#

v13.11.0

#

just switched back to 13.9 and have same issue

opal temple
#

is your bot in the server?

vocal moth
#

yeah

#

admin perms

opal temple
#

are you clearing caches maybe

#

clearing collections? sweepers?

vocal moth
#
            makeCache: Options.cacheWithLimits({
                // Keep default thread sweeping behavior
                ...Options.defaultMakeCacheSettings,
                // Override MessageManager
                MessageManager: {
                    maxSize: this.config.messageCacheMaxSize,
                    sweepInterval: this.config.messageSweepInterval,
                    sweepFilter: LimitedCollection.filterByLifetime({
                        lifetime: this.config.messageCacheLifetime,
                        getComparisonTimestamp: e => e.editedTimestamp ?? e.createdTimestamp,
                    })
                },
                GuildMemberManager: {
                    maxSize: this.config.memberCacheMaxSize
                },
                UserManager: {
                    maxSize: this.config.memberCacheMaxSize
                }
            }),```
#
ENV memberCacheMaxSize=101

ENV messageCacheMaxSize=51

ENV messageCacheLifetime=8200

ENV messageSweepInterval=1200

ENV messageEditHistoryMaxSize=1

ENV restWsBridgeTimeout=5000

ENV restTimeOffset=500

ENV restRequestTimeout=15000

ENV restSweepInterval=60

long basalt
#

yeah, we cant really help u if u have custom cache

vocal moth
#

that makes no sense

opal temple
#

for 99.9% i'm sure that you just sweep out your bot member

#

cause ```js
const clientMember = this.guild.members.resolve(this.client.user);
if (!clientMember.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return false;

#

which means that it couldn't resolve your bot member

vocal moth
#

okay

#

would this fix that xxx.interaction.guild.me.fetch()

opal temple
#

while yes, you should fix the root cause

#

there's keepOverLimit prop you can pass

#

it's a function that get's called and determines if something should be kept in the cache when it's at max size

vocal moth
#

that seems like a great solution

opal temple
#

i can't tell out of top of my head how to actually set it

#

but docs should be of help

vocal moth
#

its a start thank you

#

keepOverLimit: (member) => { return (member.id === "botid here" ) } trying out this

#

no idea how it works lol