命令.Execute不是函数



我得到的错误:

TypeError:命令。Execute不是函数在对象。执行(C:UserslachlDesktopCodingDiscord BotsrceventsclientinteractionCreate.js:11:25)在客户灵活;anonymous>(C: 用户编码 lachl 桌面 不和机器人 src 处理程序函数 handleEvents.js: 15:63)在客户端。发出(节点:事件:513:28)

handleEvents.js文件:

const fs = require("fs");
module.exports = (client) => {
client.handleEvents = async () => {
const eventFolders = fs.readdirSync(`./src/events`);
for (const folder of eventFolders) {
const eventFiles = fs
.readdirSync(`./src/events/${folder}`)
.filter((file) => file.endsWith(".js"));
switch (folder) {
case 'client':
for (const file of eventFiles) {
const event = require(`../../events/${folder}/${file}`);
if (event.once) client.once(event.name, (...args) => event.execute(...args, client));
else client.on(event.name, (...args) => event.execute(...args, client));
}
break;

default:
break;
}

}
};
};

interactionCreate.js文件:

module.exports = {
name: "interactionCreate",
async execute(interaction, client) {
if (interaction.isChatInputCommand()) {
const { commands } = client;
const { commandName } = interaction;
const command = commands.get(commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
await interaction.reply({
content: `Something went wrong while executing this command...`,
ephemeral: true,
});
}
}
},
};

handleCommands.js文件:

const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const fs = require("fs");
module.exports = (client) => {
client.handleCommands = async () => {
const commandFolders = fs.readdirSync(`./src/commands`);
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./src/commands/${folder}`)
.filter((file) => file.endsWith(".js"));
const { commands, commandArray } = client;
for (const file of commandFiles) {
const command = require(`../../commands/${folder}/${file}`);
commands.set(command.data.name, command);
commandArray.push(command.data.toJSON());
console.log(
`Command ${command.data.name} has passed through the handler`
);
}
}
const clientId = "1050985494537834606";
const guildId = "1041260203112411197";
const rest = new REST({ version: "9" }).setToken(process.env.token);
try {
console.log("Started refreshing application [/] commands");
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.commandArray,
});
console.log("Successfully reloaded application [/] commands.");
} catch (error) {
console.error(error);
}
};
};

ping.js文件:

const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription("Ping Command!"),
async exectute(interaction, client) {
const message = await interaction.deferReply({
fetchReply: true
});

const newMessage = `API LATENCY: ${client.ws.ping}nClient Ping: ${message.createdTimeStamp - interaction.createdTimeStamp}`
await interaction.editReply({
content: newMessage
});  

}
}

当我运行代码时,bot上线,但当我尝试运行命令时,它不工作

你在ping.js中拼错了execute

最新更新