Skip to content
Advertisement

TypeError: Cannot read properties of undefined (reading ‘set’) discord.js v13 slash commands handler

I am creating a Slash commands handler when i run the bot i get this error : Mainguild.SlashCommands.set(SlashComanndsArray).then(async (SlashCommand) => { TypeError: Cannot read properties of undefined (reading 'set') this is the code :


   client.on("ready", async () => {
       const Mainguild = await client.guilds.cache.get("926674245357039657");

       Mainguild.SlashCommands.set(SlashComanndsArray).then(async (SlashComanndsArray) => {
           const Roles = (SlashCommandName) => {
               const cmdPerms = SlashComanndsArray.find((c) => c.name === SlashCommandName).permission;
               if(!cmdPerms) return null;

               return Mainguild.roles.cache.filter((r) => r.permissions.has(cmdPerms));
           };
           const FullPermissions = SlashCommand.reduce((accumulator, r) => {
               const roles = Roles(r.name);
               if(!roles) return accumulator;

               const permissions = roles.reduce((a, r) => {
                   return [...a, {id: r.id, type: "ROLE", permission: true}];
               }, []);

               return [...accumulator, {id: r.id, permissions}];
           }, []);

           await Mainguild.SlashCommands.permissions.set({ FullPermissions });
       });

   })
}

also SlashComanndsArray , SlashCommand are defined and for the SlashCommands is a collection that i created id index.js with client.SlashCommands = new Collection(); the full code : https://srcb.in/BX1Ko4LuXd the index.js : https://srcb.in/qFC57vTaSn

Advertisement

Answer

  • Mainguild.SlashCommands is obviously undefined because Guild.SlashCommands is not a thing in discord.js
  • Use Guild#commands instead.
Mainguild.commands
  • Your client.SlashCommands is limited to your client. You cannot use it with a Guild.
Advertisement