const { glob } = require("glob");
const { promisify } = require("util");
const { Client } = require("discord.js");
const mongoose = require("mongoose");
const globPromise = promisify(glob);
/**
* @param {Client} portle
*/
module.exports = async (portle) => {
const commandFiles = await globPromise(`${process.cwd()}/commands/**/*.js`);
commandFiles.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (file.name) {
const properties = { directory, ...file };
portle.commands.set(file.name, properties);
}
});
const eventFiles = await globPromise(`${process.cwd()}/events/*.js`);
eventFiles.map((value) => require(value));
const slashCommands = await globPromise(
`${process.cwd()}/slash-cmds/*/*.js`
);
const arrayOfSlashCommands = [];
slashCommands.map((value) => {
const file = require(value);
if (!file?.name) return;
portle.slashCommands.set(file.name, file);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
arrayOfSlashCommands.push(file);
});
portle.on("ready", async () => {
await portle.guilds.cache
.get("884380331170484244")
.commands.set(arrayOfSlashCommands);
});
const mongooseURI = process.env.URI;
if (!mongooseURI) throw new Error("Unspecified mongoose connection string!");
mongoose.connect(mongooseURI).then(() => console.log('Connected to mongodb'));
};
我刚开始学习如何创建斜杠命令,当我创建一个后,我重启了我的机器人 我的命令截图 ,现在我的一条斜杠命令被复制了。 我该如何删除重复的命令?
下面是命令和事件处理程序代码,我在YouTube教程中找到的。