-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
53 lines (44 loc) · 1.85 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ChannelType } = require("discord.js");
const logSchema = require("../../Models/Logs");
module.exports = {
data: new SlashCommandBuilder()
.setName("setup-logs")
.setDescription("Set up your logging channel for the audit logs.")
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addChannelOption(option =>
option.setName("channel")
.setDescription("Channel for logging messages.")
.setRequired(false)
),
async execute(interaction) {
const { channel, guildId, options } = interaction;
const logChannel = options.getChannel("channel") || channel;
const embed = new EmbedBuilder();
logSchema.findOne({ Guild: guildId }, async (err, data) => {
if (!data) {
await logSchema.create({
Guild: guildId,
Channel: logChannel.id
});
embed.setDescription("Data was succesfully sent to the database.")
.setColor("Green")
.setTimestamp();
} else if (data) {
logSchema.findOneAndDelete({ Guild: guildId });
await logSchema.create({
Guild: guildId,
Channel: logChannel.id
});
embed.setDescription("Old data was succesfully replaced with the new data.")
.setColor("Green")
.setTimestamp();
}
if (err) {
embed.setDescription("Something went wrong. Please contact the developers")
.setColor("Red")
.setTimestamp();
}
return interaction.reply({ embeds: [embed], ephemeral: true });
})
}
}