我正在创建一个具有多个斜杠命令的bot不管我怎么做它都会显示错误
我尝试了。editreply(),甚至if (interaction.replied = true) {interaction.replied = false}
顺便说一下,我使用ES模块。下面是我的代码:
import {
Client,
EmbedBuilder,
GatewayIntentBits,
Routes,
SlashCommandBuilder,
} from "discord.js";
import { config } from "dotenv";
import { REST } from "@discordjs/rest";
config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const token = process.env.token;
const rest = new REST({ version: "10" }).setToken(token);
const CLIENT_ID = process.env.CLIENT_ID;
client.on("ready", () => {
console.log(`${client.user.tag} is ready!`);
});
const embed = new EmbedBuilder()
.setTitle("noobs.")
.setColor("Aqua")
.setDescription("hm.");
client.on("interactionCreate", (interaction) => {
// if (interaction.commandName == "ping") {
// interaction.reply({content: "pong!"})
// }
if (interaction.options.getString("food") == "gi") {
interaction.reply({ content: "pong" });
// if (interaction.replied = true) {
// interaction.replied = false
// }
if (interaction.options.getString("food") != "gi") {
interaction.reply({ embeds: [embed] });
}
}
if ((interaction.commandName = "hello")) {
interaction.reply({ content: "*gives love* hi" });
}
});
const commands = [
{
name: "ping",
description: "Replies with Pong!",
options: [
{
name: "food",
description: "ur mom",
type: 3,
required: true,
},
],
},
{
name: "hello",
description: "Greets you with love.",
},
];
async function main() {
try {
console.log("Loading application (/) commands.");
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
console.log("Successfully reloaded application (/) commands.");
} catch (err) {
console.log(err);
}
}
main();
client.login(token);
不能将interaction.replied
设置为false。如果您已经回复了交互,您只能使用interaction.editReply()
或interaction.followUp()
.
所以尝试检查if(!interaction.replied) {}
并将您的代码放入花括号中。