@discordjs/rest

Hi i just installed discordjs/rest for slash commands but there is a error message now someone know how to fix it
5 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
MrMythical
MrMythical16mo ago
You left out lots of important details Read this ^
Thebluehusky
ThebluehuskyOP16mo ago
const Discord = require('discord.js')
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v10")

module.exports = async bot => {

let commands = [];

bot.commands.forEach(async command => {

let slashcommand = new Discord.SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description)
.setDMPermission(command.dm)
.setDefaultMemberPermissions(command.permission === "Aucune" ? null : command.permission)

if(command.options?.length >= 1) {
for(let i = 0; i < command.options.length; i++) {
slashcommand[`add${command.options[i].type.slice(0,1).toLowerCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
}
}

await commands.push(slashcommand)
})

const rest = new REST ({version: "10"}).setToken(bot.token)

await rest.put(Routes.applicationCommand(bot.user.id), {body: commands})
console.log("Les slash commandes ont été ajoutées")
}
const Discord = require('discord.js')
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v10")

module.exports = async bot => {

let commands = [];

bot.commands.forEach(async command => {

let slashcommand = new Discord.SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description)
.setDMPermission(command.dm)
.setDefaultMemberPermissions(command.permission === "Aucune" ? null : command.permission)

if(command.options?.length >= 1) {
for(let i = 0; i < command.options.length; i++) {
slashcommand[`add${command.options[i].type.slice(0,1).toLowerCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
}
}

await commands.push(slashcommand)
})

const rest = new REST ({version: "10"}).setToken(bot.token)

await rest.put(Routes.applicationCommand(bot.user.id), {body: commands})
console.log("Les slash commandes ont été ajoutées")
}
here is the script
node:events:492
throw er; // Unhandled 'error' event
^

DiscordAPIError[0]: 405: Method Not Allowed
at handleErrors (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:1072:23)
at async SequentialHandler.queueRequest (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:913:14)
at async _REST.request (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async module.exports (C:\Users\Hp\Desktop\Botv14\Loaders\loadSlashCommands.js:28:5)
at async module.exports (C:\Users\Hp\Desktop\Botv14\Events\ready.js:6:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:395:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: undefined,
json: [
SlashCommandBuilder {
options: [],
name: 'ping',
name_localizations: undefined,
description: 'Affiche la latence du bot',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: null,
dm_permission: false,
nsfw: undefined
}
]
},
rawError: { message: '405: Method Not Allowed', code: 0 },
code: 0,
status: 405,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1139567824604516443/commands/undefined'
}

Node.js v18.17.0
node:events:492
throw er; // Unhandled 'error' event
^

DiscordAPIError[0]: 405: Method Not Allowed
at handleErrors (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:1072:23)
at async SequentialHandler.queueRequest (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:913:14)
at async _REST.request (C:\Users\Hp\Desktop\Botv14\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async module.exports (C:\Users\Hp\Desktop\Botv14\Loaders\loadSlashCommands.js:28:5)
at async module.exports (C:\Users\Hp\Desktop\Botv14\Events\ready.js:6:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:395:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: undefined,
json: [
SlashCommandBuilder {
options: [],
name: 'ping',
name_localizations: undefined,
description: 'Affiche la latence du bot',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: null,
dm_permission: false,
nsfw: undefined
}
]
},
rawError: { message: '405: Method Not Allowed', code: 0 },
code: 0,
status: 405,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1139567824604516443/commands/undefined'
}

Node.js v18.17.0
and here is the error message
MrMythical
MrMythical16mo ago
It's Routes.applicationCommands
Thebluehusky
ThebluehuskyOP16mo ago
oh my bad thx it work
Want results from more Discord servers?
Add your server