【发布时间】:2021-08-15 20:10:26
【问题描述】:
我对 discord.js 斜杠命令有疑问。
正如您在我的代码中看到的,我将名称设置为“姓名”和“年龄”,所以我不明白问题出在哪里。
这是我的错误:
error: (node:16004) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
options[0].name: Command name is invalid
这是我的代码:
const Discord = require('discord.js');
require("dotenv").config();
const client = new Discord.Client();
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const getApp = (guildid) => {
const app = client.api.applications(client.user.id);
if(guildid){
app.guilds(guildid);
}
return app;
}
await getApp("842486032842358784").commands.post({
data: {
name: 'embed',
description: 'Displays embed',
options: [
{
name: 'Name',
description: 'Your Name',
required: true,
type: 3
},
{
name: 'Age',
description: 'Your Age',
required: false,
type: 4
}
]
},
})
client.ws.on('INTERACTION_CREATE', async(interaction) => {
const command = interaction.data.name.toLowerCase();
const { name, options } = interaction.data;
console.log(options);
if(command === "embed"){
reply(interaction, 'hi');
}
})
const reply = (interaction, response) => {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: response,
}
}
})
}
});
client.login(process.env.TOKEN);
【问题讨论】:
-
请仅在您的问题中添加必要的信息。不需要将其添加到末尾。
标签: javascript node.js discord discord.js