Home > database >  Discord.js issues with default member permissions
Discord.js issues with default member permissions

Time:12-30

I'm trying to restrict the use of a slash command using the setDefaultMemberPermissions attribute that is supposed to take permission and then check to see if a user meets the requirements to execute a command however for some reason I cannot get the permissions to work

As shown in the official documentation I did the following:

const { PermissionFlagsBits } = require('discord.js');

new SlashCommandBuilder()
        .setName('e')
        .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers),

this resulted in an undefined error

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

CodePudding user response:

I believe you are looking at the current version of discord.js documentation. For slash command permissions in v13 you need to import PermissionFlagsBits from a separate place:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { PermissionFlagsBits } = require('discord-api-types/v10');

const data = new SlashCommandBuilder()
    .setName('ban')
    .setDescription('Ban a member!')
    .addUserOption(option =>
        option.setName('target').setDescription('The member to ban'))
    .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers | PermissionFlagsBits.BanMembers);

see v13 docs

  • Related