为啥 Discord API 返回错误 405 以向公会添加斜杠命令?
Posted
技术标签:
【中文标题】为啥 Discord API 返回错误 405 以向公会添加斜杠命令?【英文标题】:Why is Discord API returning error 405 for adding a slash command to a guild?为什么 Discord API 返回错误 405 以向公会添加斜杠命令? 【发布时间】:2022-01-20 18:35:19 【问题描述】:我目前正在 discord.js 中制作一个机器人,并且我正在尝试构建一个命令处理程序(专门用于斜杠命令)。不幸的是,每当我运行代码时,它都会从 discord API 返回 405 错误。这是错误:
DiscordAPIError[0]: 405: Method Not Allowed
at SequentialHandler.runRequest (/home/ayman/Documents/Projects/image-bot/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.js:198:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (/home/ayman/Documents/Projects/image-bot/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.js:99:20)
at async /home/ayman/Documents/Projects/image-bot/src/main.js:35:5
rawError: message: '405: Method Not Allowed', code: 0 ,
code: 0,
status: 405,
method: 'put',
url: 'https://discord.com/api/v9/applications/921468165576347658/guilds/545334770368774146/commands/undefined'
这是有问题的代码:
(async () =>
try
if (process.env.ENV === "production")
await rest.put(Routes.applicationCommand(CLIENT_ID),
body: commands,
);
console.log("Commands successfully registered globally.");
else
await rest.put(Routes.applicationGuildCommand(CLIENT_ID, process.env.GUILD_ID),
body: commands,
);
console.log("Commands successfully registered locally.");
catch (err)
if (err) console.error(err);
)();
发生这种情况有什么原因吗?感谢您的帮助!
【问题讨论】:
【参考方案1】:你用错了方法,是applicationGuildCommands
:)
参考source code
【讨论】:
以上是关于为啥 Discord API 返回错误 405 以向公会添加斜杠命令?的主要内容,如果未能解决你的问题,请参考以下文章
从 AngularJS POST 到 Django API 以获取 JWT 并返回 405 错误
为啥我在尝试使用 reddit API 时会收到 405 错误?