#Getting client permissions

38 messages · Page 1 of 1 (latest)

dense river
#

I'm trying to check for client's permissions for a command, just in case the bot ends up not having the right permissions. I've tried if (command.userPerms && !interaction.guild.me.permissions.has(command.userPerms)), but it says permissions is undefined.

serene tangle
#

what is command.userPerms?

dense river
#

it's an array of the permissions flags

#

for each command

#

I think i'm not accessing the client's permissions correctly

#

im not sure what the correct way is

serene tangle
#

can you please log and show it

dense river
#

log?

#

TypeError: Cannot read properties of undefined (reading 'permissions')

serene tangle
#

yeah, console.log(command.userPerms)

dense river
#

it's just

#

"ADMINISTRATOR"

#

oh

#

I realized in my description it says userPerms

#

I meant to say botPerms

#

disregard userPerms

serene tangle
#

also, what is interaction? is this code callbacking after you execute a command?

dense river
#

its a parameter

#

it's in my interactionCreate event

serene tangle
dense river
#

I got a guild object

serene tangle
#

can you please show the full code

dense river
#
  guild: <ref *1> Guild {
    id: '964924694367174677',
    name: 'Parallax Testing',
    icon: '2085bcaf216ba49a4517efe29607e889',
    features: [],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    scheduledEvents: GuildScheduledEventManager { guild: [Circular *1] },
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 'NONE',
    vanityURLCode: null,
    nsfwLevel: 'DEFAULT',
    premiumSubscriptionCount: 0,
    discoverySplash: null,
    memberCount: 7,
    large: false,
    premiumProgressBarEnabled: false,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: '964924694987948098',
    premiumTier: 'NONE',
    explicitContentFilter: 'DISABLED',
    mfaLevel: 'NONE',
    joinedTimestamp: 1655578962204,
    defaultMessageNotifications: 'ALL_MESSAGES',
    systemChannelFlags: SystemChannelFlags { bitfield: 0 },
    maximumMembers: 500000,
    maximumPresences: null,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: null,
    publicUpdatesChannelId: null,
    preferredLocale: 'en-US',
    ownerId: '310422534975782932',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  joinedTimestamp: 1655578962204,
  premiumSinceTimestamp: null,
  nickname: null,
  pending: false,
  communicationDisabledUntilTimestamp: null,
  _roles: [ '987794504339816501' ],
  user: ClientUser {
    id: '730883332849532949',
    bot: true,
    system: false,
    flags: UserFlags { bitfield: 0 },
    username: 'Parallax Beta',
    discriminator: '4311',
    avatar: 'efd23f446c9e553b90cff17f41469995',
    banner: undefined,
    accentColor: undefined,
    verified: true,
    mfaEnabled: true
  },
  avatar: null
}```
serene tangle
#

i mean your code, not log

dense river
#
        command.botPerms &&
        !interaction.guild.me.permissions.has(command.botPerms) //check for client's permission
      ) {
        return interaction.reply({
          ephemeral: true,
          embeds: [
            new MessageEmbed()
              .setColor(Embed.wrongcolor)
              .setDescription(
                `${
                  Emoji.Message.ERROR
                } I don't have the required permissions to use this command\n \`${command.botPerms.join(
                  `, `
                )}\``
              )
              .setFooter(`${Embed.footertext}`, client.user.displayAvatarURL()),
          ],
        });
      }```
serene tangle
dense river
#

yes

#

I do

serene tangle
#

can you try changing permissions.has(command.botPerms) to permissions.has('ADMINISTRATOR'), just to try

#

because it's very strange, everything is alright

dense river
#

testing it right now

#

console logging is giving me true...

#

i will try uncommenting and see if it works

#

....

#

it works now?

#

alright then

#

not sure what the issue was, all I did was console log the same thing

#

thank you for your assistance/time