Permission check in other guild

How am I supposed to make it so for example I have Invite to MTF context menu that has to invite someone to MTF guild, like, it does its job, but my point is so no person can be invited unless they have Lieutenant+ in MTF guild, how am I supposed to make this permission check? (i'd appreciate if i were to be pinged upon reply)
Solution:
@Boomeravna @UndiedGFX I got it fixed. Instead of passing just userid, I passed entire member object & did member.fetch(true) and of course made sure I am fetched in the 'mtf' guild. Hopefully it is understood
Jump to solution
26 Replies
Favna
Favna•4mo ago
make a precondition and in that precondition use this.container.client.guilds.get('the id of the other guild').roles.get('the id of the role') and then do the checks you want to do.
Shrewd 💫
Shrewd 💫OP•4mo ago
i'll see it soon So apparently it does work but my command seems to do check only for the first time It doesn't care if someones role was removed, it will still execute it And yes, I do fetch it
Favna
Favna•4mo ago
show code pls
Shrewd 💫
Shrewd 💫OP•4mo ago
const { Precondition } = require('@sapphire/framework');

class IsMTFHR extends Precondition {
async messageRun(message) {
return this.checkMTFHR(message.author.id);
}

async chatInputRun(interaction) {
return this.checkMTFHR(interaction.user.id);
}

async contextMenuRun(interaction) {
return this.checkMTFHR(interaction.user.id);
}

async checkMTFHR(userId) {
const mtfGuild = this.container.client.guilds.get('1197963703069446295');
const lieutenantRole = mtfGuild.roles.get('1198010419500023809');

try {
const member = await mtfGuild.members.fetch(userId, { force: true });

if (member.roles.cache.has(lieutenantRole.id)) {
return this.ok();
} else {
return this.error({
message: 'Insufficient permissions. You need to be Lieutenant or higher to execute this command.'
});
}
} catch (error) {
return this.error({ message: 'An error occurred while checking your role. Please try again later.' });
}
}
}

module.exports = {
IsMTFHR
};
const { Precondition } = require('@sapphire/framework');

class IsMTFHR extends Precondition {
async messageRun(message) {
return this.checkMTFHR(message.author.id);
}

async chatInputRun(interaction) {
return this.checkMTFHR(interaction.user.id);
}

async contextMenuRun(interaction) {
return this.checkMTFHR(interaction.user.id);
}

async checkMTFHR(userId) {
const mtfGuild = this.container.client.guilds.get('1197963703069446295');
const lieutenantRole = mtfGuild.roles.get('1198010419500023809');

try {
const member = await mtfGuild.members.fetch(userId, { force: true });

if (member.roles.cache.has(lieutenantRole.id)) {
return this.ok();
} else {
return this.error({
message: 'Insufficient permissions. You need to be Lieutenant or higher to execute this command.'
});
}
} catch (error) {
return this.error({ message: 'An error occurred while checking your role. Please try again later.' });
}
}
}

module.exports = {
IsMTFHR
};
this.container.client.guilds.get is not a function is also what I get in the console, and I've just noticed it
UndiedGFX
UndiedGFX•4mo ago
because guilds.get is not a method? it is pre djs v12 it is guilds.cache.get
Shrewd 💫
Shrewd 💫OP•4mo ago
yeah I didnt realize, just followed the example above
UndiedGFX
UndiedGFX•4mo ago
the same should be done for RoleManager and ChannelManager instances
Shrewd 💫
Shrewd 💫OP•4mo ago
Alright I've fixed it but still, the issue persists within role remove
UndiedGFX
UndiedGFX•4mo ago
as i said
Shrewd 💫
Shrewd 💫OP•4mo ago
So like let me explain
UndiedGFX
UndiedGFX•4mo ago
these two lines, are obselete
const mtfGuild = this.container.client.guilds.get('1197963703069446295');
const lieutenantRole = mtfGuild.roles.get('1198010419500023809');
const mtfGuild = this.container.client.guilds.get('1197963703069446295');
const lieutenantRole = mtfGuild.roles.get('1198010419500023809');
it should be guilds.cache.get and roles.cache.get and about the "role remove", your code doesnt do anything like that, so i do not understand
Shrewd 💫
Shrewd 💫OP•4mo ago
Yeah because I tried to elaborate and I didn't For example someones role gets removed, he still is able to execute the command as if nothing had happened
UndiedGFX
UndiedGFX•4mo ago
can you like try fetching roles before running the if, maybe discord.js didnt update the cache even though it should remove the role from cache
Shrewd 💫
Shrewd 💫OP•4mo ago
So you expect me to just update them to add cache.get to it? sorry Im just a little overwhelmed I'm swapping it
UndiedGFX
UndiedGFX•4mo ago
no, what i meant was djs should update the member roles cache when the role is removed maybe try this again, the issue should not happen
Shrewd 💫
Shrewd 💫OP•4mo ago
The application did not respond Also do I revert that or
const mtfGuild = this.container.client.guilds.get('1197963703069446295');
const lieutenantRole = mtfGuild.roles.get('1198010419500023809');
const mtfGuild = this.container.client.guilds.get('1197963703069446295');
const lieutenantRole = mtfGuild.roles.get('1198010419500023809');
d.js docs
d.js docs•4mo ago
:class: GuildManager @14.15.3 Manages API methods for Guilds and stores their cache.
Shrewd 💫
Shrewd 💫OP•4mo ago
Oh lord this discord formatting Let me read
UndiedGFX
UndiedGFX•4mo ago
according to the docs, <guilds>.get does not exist it should be .cache.get
Shrewd 💫
Shrewd 💫OP•4mo ago
Oh wait I had old lines copied Yeah, I have it set to .cache.get That's the issue I am facing now
UndiedGFX
UndiedGFX•4mo ago
and what exactly is causing that
Shrewd 💫
Shrewd 💫OP•4mo ago
Oh, well, didn't have the role but yeah, the issue is as I have mentioned If I update my role when my bot is online, it would still execute it Or if I ran the bot without roles and then give myself the role, it won't execute thinking I don't have it
UndiedGFX
UndiedGFX•4mo ago
"my" are you sure you dont have an OwnerOnly precondition as well wrapped up in the command?
Shrewd 💫
Shrewd 💫OP•4mo ago
preconditions: ['IsMTFHR'], And the precondition code you've got The context menu does not have anything that would restrict it It does not have anything regarding permissions, just IsMTFHR precondition So yeah, I haven't found a fix to it
Solution
Shrewd 💫
Shrewd 💫•4mo ago
@Boomeravna @UndiedGFX I got it fixed. Instead of passing just userid, I passed entire member object & did member.fetch(true) and of course made sure I am fetched in the 'mtf' guild. Hopefully it is understood
Shrewd 💫
Shrewd 💫OP•4mo ago
Thank you for your help though
Want results from more Discord servers?
Add your server