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 :
JavaScript
x
28
28
1
2
client.on("ready", async () => {
3
const Mainguild = await client.guilds.cache.get("926674245357039657");
4
5
Mainguild.SlashCommands.set(SlashComanndsArray).then(async (SlashComanndsArray) => {
6
const Roles = (SlashCommandName) => {
7
const cmdPerms = SlashComanndsArray.find((c) => c.name === SlashCommandName).permission;
8
if(!cmdPerms) return null;
9
10
return Mainguild.roles.cache.filter((r) => r.permissions.has(cmdPerms));
11
};
12
const FullPermissions = SlashCommand.reduce((accumulator, r) => {
13
const roles = Roles(r.name);
14
if(!roles) return accumulator;
15
16
const permissions = roles.reduce((a, r) => {
17
return [a, {id: r.id, type: "ROLE", permission: true}];
18
}, []);
19
20
return [accumulator, {id: r.id, permissions}];
21
}, []);
22
23
await Mainguild.SlashCommands.permissions.set({ FullPermissions });
24
});
25
26
})
27
}
28
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 becauseGuild.SlashCommands
is not a thing in discord.js- Use Guild#commands instead.
JavaScript
1
2
1
Mainguild.commands
2
- Your
client.SlashCommands
is limited to yourclient
. You cannot use it with aGuild
.