I'm making a new discord bot to help me learn discordjs and JS in general but I keep getting the following HTTP error and cannot find a way to resolve it. Using discord.js version 13.8.0
See error message:
DiscordAPIError: 405: Method Not Allowed
at RequestHandler.execute (C:\Users\Offic\Desktop\___\LearningBot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\Offic\Desktop\___\LearningBot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async ApplicationCommandPermissionsManager.set (C:\Users\Offic\Desktop\___\LearningBot\node_modules\discord.js\src\managers\ApplicationCommandPermissionsManager.js:186:18)
at async C:\Users\Offic\Desktop\___\LearningBot\handlers\commands.js:66:12 {
method: 'put',
path: '/applications/986771474943709244/guilds/986441402735022140/commands/permissions',
code: 0,
httpStatus: 405,
requestData: { json: [], files: [] }
The following is the faulty code snippet:
client.on("ready", async () => {
const MainGuild = await client.guilds.cache.get(process.env.GUILDID);
MainGuild.commands.set(commandsarray).then(async (command) => {
const Roles = (commandname) => {
const cmdperms = commandsarray.find((c) => c.name === commandname).permission;
if(!cmdperms) return null;
return MainGuild.roles.cache.filter((r) => r.permissions.has(cmdperms));
}
const fullPermissions = command.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.commands.permissions.set({ fullPermissions });
});
});
The section where the error occurs is:
await MainGuild.commands.permissions.set({ fullPermissions });