124 lines
4.2 KiB
JavaScript
124 lines
4.2 KiB
JavaScript
const { Client, Collection, Events, EmbedBuilder, GatewayIntentBits, Partials } = require('discord.js');
|
|
const { token } = require('./config.json');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const informationStatus = "[INFO]: ";
|
|
const warningStatus = "[WARNING]: ";
|
|
const errorStatus = "[ERROR]: ";
|
|
|
|
const starChannelID = "1211566862148567091";
|
|
|
|
const client = new Client({
|
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions],
|
|
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
|
});
|
|
|
|
client.commands = new Collection();
|
|
|
|
const foldersPath = path.join(__dirname, 'commands');
|
|
const commandFolders = fs.readdirSync(foldersPath);
|
|
|
|
for (const folder of commandFolders) {
|
|
const commandsPath = path.join(foldersPath, folder);
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
|
|
console.log(informationStatus + `'${folder}' folder has been added! All js files will be called.`);
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
|
|
if('data' in command && 'execute' in command) {
|
|
client.commands.set(command.data.name, command)
|
|
} else {
|
|
console.log(warningStatus + `This file at ${filePath} does not contain data or execute properties, will be ignored.`);
|
|
}
|
|
|
|
console.log(informationStatus + `'${file}' has been added into command pool.`);
|
|
}
|
|
}
|
|
|
|
client.once(Events.ClientReady, readyClient => {
|
|
try {
|
|
client.user.setPresence({ activities: [{ name: 'Use /help - MBot' }], status: 'idle' });
|
|
console.log(informationStatus + `Activity has been set to '${client.user.presence.activities}'`);
|
|
console.log(informationStatus + `Status has been set to ${client.user.presence.status}`);
|
|
} catch (error) {
|
|
console.log(errorStatus + "Something went wrong with setting the status! Debug information below.");
|
|
console.error(error);
|
|
}
|
|
|
|
console.log(informationStatus + "Client is online!");
|
|
});
|
|
|
|
client.on(Events.InteractionCreate, async interaction => {
|
|
if(!interaction.isChatInputCommand()) return;
|
|
|
|
const command = interaction.client.commands.get(interaction.commandName);
|
|
|
|
if(!command) {
|
|
console.log(errorStatus + "No commands matching ${interaction.commandName} was not found! (Repair!)")
|
|
console.error(error);
|
|
}
|
|
|
|
try {
|
|
await command.execute(interaction);
|
|
} catch (error) {
|
|
console.console(errorStatus + "Something went wrong while executing this command! Please use the information below and sudmit to the author of the issue!");
|
|
console.error(error);
|
|
if(interaction.replied || interaction.deferred) {
|
|
await interaction.followUp({ content: 'Error executing this command! Something went wrong, try again later.', ephemeral: true });
|
|
} else {
|
|
await interaction.reply({ content: 'Error executing this command! Something went wrong, try again later.', ephemeral: true });
|
|
}
|
|
}
|
|
});
|
|
|
|
client.on(Events.MessageReactionAdd, async (reaction, user) => {
|
|
try {
|
|
await reaction.fetch();
|
|
console.log(informationStatus + "Reaction noticed!");
|
|
|
|
const starChannel = client.channels.cache.get(starChannelID);
|
|
|
|
if (reaction.emoji.name == '⭐') {
|
|
if (reaction.count <= 1) {
|
|
const starEmbed = {
|
|
color: 0x0F3061,
|
|
author: {
|
|
name: reaction.message.author.tag,
|
|
icon_url: reaction.message.author.displayAvatarURL(),
|
|
},
|
|
footer: {
|
|
text: new Date().toLocaleString(),
|
|
},
|
|
};
|
|
|
|
if(reaction.message.attachments.first()){
|
|
starEmbed.image = {
|
|
url: reaction.message.attachments.first().url,
|
|
};
|
|
}
|
|
|
|
if(!reaction.message.content == '') {
|
|
starEmbed.description = reaction.message.content;
|
|
}
|
|
|
|
starChannel.send({ embeds: [starEmbed] });
|
|
console.log(informationStatus + "Star message has been added!");
|
|
} else {
|
|
return;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
} catch(error) {
|
|
console.log(errorStatus + 'Something wrong happend while fetching reactions for message! Please use information below to debug.');
|
|
console.error(error);
|
|
}
|
|
});
|
|
|
|
|
|
client.login(token);
|