【发布时间】:2021-11-09 06:18:31
【问题描述】:
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'));
};
我刚开始学习如何制作斜杠命令,当我制作一个时,我重新启动了我的机器人Image of my commands,现在我的一个斜杠命令被复制了。我将如何删除重复项?
下面的命令和事件处理程序代码,我在 yt 教程中找到的。
【问题讨论】:
-
欢迎来到 SO。请附上实际代码。
标签: discord.js