Search code examples
discorddiscord.js

Checking if my bot has permissions to create channels. in V14


Im trying to make sure my bot has permissions to make channels before running the command to avoid and errors, here's the code i have:

if (!interaction.guild.me.permissions.has("ADMINISTRATOR")) {
  interaction.reply("I Dont have perms to create channels");;
}

yet i still get this error:

        if (!interaction.guild.me.permissions.has("ADMINISTRATOR")) {
                                  ^

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

did they change something in the new v14? thanks in advance.


Solution

  • Just need to access the GuildMemberManager before the me object, but you also should use the PermissionsBitField object to reference a permission:

    if (!interaction.guild.members.me.permissions.has(PermissionsBitField.Flags.Administrator)) {
        interaction.reply("I don't have permissions to create channels");
    }