Thebluehusky
Thebluehusky
DIAdiscord.js - Imagine an app
Created by Thebluehusky on 8/11/2023 in #djs-questions
@discordjs/rest
thx it work
11 replies
DIAdiscord.js - Imagine an app
Created by Thebluehusky on 8/11/2023 in #djs-questions
@discordjs/rest
oh my bad
11 replies
DIAdiscord.js - Imagine an app
Created by Thebluehusky on 8/11/2023 in #djs-questions
@discordjs/rest
and here is the error message
11 replies
DIAdiscord.js - Imagine an app
Created by Thebluehusky on 8/11/2023 in #djs-questions
@discordjs/rest
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
11 replies
DIAdiscord.js - Imagine an app
Created by Thebluehusky on 8/11/2023 in #djs-questions
@discordjs/rest
here is the script
11 replies
DIAdiscord.js - Imagine an app
Created by Thebluehusky on 8/11/2023 in #djs-questions
@discordjs/rest
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")
}
11 replies