【发布时间】:2021-08-16 15:39:31
【问题描述】:
我更改了我的命令处理程序,并且不再从 profileData 中导出任何内容(以前是命令处理程序文件)。该文件正在检查他们的个人资料并将数据保存在 profileData 中,或者如果他们没有,则为他们创建一个。我想导出 profileData 以在其他文件中使用,而不是在每个命令中查询。我怎样才能做到这一点。我已经尝试将 module.exports 和 exports.profileData = profileData 放在所有地方,但没有任何效果,我只是迷失了如何做到这一点。任何帮助将不胜感激。
profileData-
const profileModel = require("../../models/profileSchema");
module.exports = (client) => {
client.on("message", async (message) => {
const prefix = 's!'
if (!message.content.startsWith(prefix) || message.author.bot) return;
try {
const profileData = await profileModel.findOne({ userID: message.author.id });
if (!profileData) {
let profile = await profileModel.create({
userID: message.author.id,
serverID: message.guild.id,
coins: 10,
bank: 0,
});
profile.save();
}
} catch (err) {
console.log(err);
}
})
}
module.exports.config = {
displayName: 'Profile Data',
dbName: 'PROFILEDATA',
loadDBFirst: true
}
余额-
const { MessageEmbed } = require("discord.js");
const { profileData } = require("../../Features/client/profileData");
module.exports = {
name: "balance",
aliases: ["bal"],
category: "Economy",
cooldown: "20s",
permissions: ["ADMINISTRATOR"],
maxArgs: 0,
description: "Check your wallet and bank balance!",
execute: async ({ message, client }) => {
let balPlaceholder = "'s balance";
const BalEmbed = new MessageEmbed()
.setColor("#0bbffc")
.setAuthor("Saoul 2")
.setTitle(`${message.author.username}${balPlaceholder}`)
.addFields(
{ name: "???? Wallet:", value: `${profileData.coins}`, inline: true },
{ name: "???? Bank:", value: `${profileData.bank}`, inline: true }
)
.setTimestamp()
.setFooter(
`Command Requested By ${message.author.tag}`,
client.user.displayAvatarURL()
);
message.channel.send(BalEmbed);
},
};
【问题讨论】:
标签: javascript node.js mongodb mongodb-query discord.js