Discord.js 不會再次注冊我的命令,盡管它們不存在。我已經通過運行驗證了這些命令不存在:
rest.get(Routes.applicationCommands(clientId))
.then(data => console.log(data));
唯一的回應是[]
我得到的錯誤是這樣的:
DiscordAPIError[50035]: Invalid Form Body
method: 'PUT',
url: 'https://discord.com/api/v9/applications/985234455717363762/commands',
requestBody: {
files: undefined,
json: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
]
}
}
代碼 ( deploy-commands.js) 如下所示:
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, token } = require('./config.json');
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(token);
rest.put(Routes.applicationCommands(clientId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
使用此檔案樹:
discord-bot/
|-- Commands/
|-- avatar.js
|-- beep.js
|-- kick.js
|-- options-info.js
|-- ping.js
|-- prune.js
|-- server.js
|-- user-info.js
|-- node_modules
|-- config.json
|-- deploy-commands.js
|-- index.js
|-- package-lock.json
|-- package.json
幫助!
uj5u.com熱心網友回復:
如果您有 2 個具有相同名稱的應用程式命令,則會出現此錯誤,請仔細檢查您的命令名稱并確保每個命令都有一個唯一的名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/489904.html
標籤:javascript 节点.js json 休息 不和谐.js
