mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-10 10:43:06 +00:00
Fixes and Improvements
This commit is contained in:
parent
4c5a8d2e66
commit
82f354db1c
12 changed files with 137 additions and 105 deletions
|
@ -1,11 +1,11 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { Client, Collection, Events, GatewayIntentBits } from "discord.js";
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { Client, Collection, Events, GatewayIntentBits } from 'discord.js';
|
||||
|
||||
import { deployCommands } from "./util/deployCommand.js";
|
||||
import { getAllMembers, setMembers } from "./util/db.js";
|
||||
import { deployCommands } from './util/deployCommand.js';
|
||||
import { removeMember, setMembers } from './util/db.js';
|
||||
|
||||
const config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
||||
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
|
||||
const { token, guildId } = config;
|
||||
|
||||
const client: any = new Client({
|
||||
|
@ -16,35 +16,38 @@ client.commands = new Collection();
|
|||
try {
|
||||
const __dirname = path.resolve();
|
||||
|
||||
const commandsPath = path.join(__dirname, "/target/commands/");
|
||||
const commandsPath = path.join(__dirname, '/target/commands/');
|
||||
const commandFiles = fs
|
||||
.readdirSync(commandsPath)
|
||||
.filter((file) => file.endsWith(".js"));
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join("file://", commandsPath, file);
|
||||
const filePath = path.join('file://', commandsPath, file);
|
||||
const commandModule = await import(filePath);
|
||||
const command = commandModule.default;
|
||||
|
||||
if (
|
||||
command instanceof Object &&
|
||||
"data" in command &&
|
||||
"execute" in command
|
||||
'data' in command &&
|
||||
'execute' in command
|
||||
) {
|
||||
client.commands.set(command.data.name, command);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
console.log(
|
||||
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
}
|
||||
catch (error: any) {
|
||||
console.log(`Error while getting commands up: ${error}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await deployCommands();
|
||||
} catch (error: any) {
|
||||
}
|
||||
catch (error: any) {
|
||||
console.log(`Error while registering commands: ${error}`);
|
||||
}
|
||||
|
||||
|
@ -70,20 +73,34 @@ client.on(Events.InteractionCreate, async (interaction: any) => {
|
|||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({
|
||||
content: "There was an error while executing this command!",
|
||||
content: 'There was an error while executing this command!',
|
||||
ephemeral: true,
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
await interaction.reply({
|
||||
content: "There was an error while executing this command!",
|
||||
content: 'There was an error while executing this command!',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.on(Events.GuildMemberAdd, async () => {
|
||||
const guild = await client.guilds.fetch(guildId);
|
||||
const members = await guild.members.fetch();
|
||||
const nonBotMembers = members.filter((member: any) => !member.user.bot);
|
||||
|
||||
await setMembers(nonBotMembers);
|
||||
});
|
||||
|
||||
client.on(Events.GuildMemberRemove, async (member: any) => {
|
||||
await removeMember(member.user.id);
|
||||
});
|
||||
|
||||
client.login(token);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue