mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-14 04:33:05 +00:00
Fixes and Improvements
This commit is contained in:
parent
4c5a8d2e66
commit
82f354db1c
12 changed files with 137 additions and 105 deletions
|
@ -1,12 +1,12 @@
|
|||
import fs from "node:fs";
|
||||
import pkg from "pg";
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { memberTable } from "../db/schema.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
import fs from 'node:fs';
|
||||
import pkg from 'pg';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import { memberTable } from '../db/schema.js';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
const { Pool } = pkg;
|
||||
const config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
||||
const { dbConnectionString, guildId } = config;
|
||||
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
|
||||
const { dbConnectionString } = config;
|
||||
|
||||
const dbPool = new Pool({
|
||||
connectionString: dbConnectionString,
|
||||
|
@ -29,7 +29,8 @@ export async function setMembers(nonBotMembers: any) {
|
|||
.update(memberTable)
|
||||
.set({ discordUsername: member.user.username })
|
||||
.where(eq(memberTable.discordId, member.user.id));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
const members: typeof memberTable.$inferInsert = {
|
||||
discordId: member.user.id,
|
||||
discordUsername: member.user.username,
|
||||
|
@ -38,3 +39,7 @@ export async function setMembers(nonBotMembers: any) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeMember(discordId: string) {
|
||||
await db.delete(memberTable).where(eq(memberTable.discordId, discordId));
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import { REST, Routes } from "discord.js";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { REST, Routes } from 'discord.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
||||
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
|
||||
const { token, clientId, guildId } = config;
|
||||
|
||||
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'));
|
||||
|
||||
const rest = new REST({ version: "9" }).setToken(token);
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
export const deployCommands = async () => {
|
||||
try {
|
||||
|
@ -20,13 +20,14 @@ export const deployCommands = async () => {
|
|||
);
|
||||
|
||||
const commands = commandFiles.map(async (file) => {
|
||||
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) {
|
||||
if (command instanceof Object && 'data' in command) {
|
||||
return command.data.toJSON();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
console.log(
|
||||
`[WARNING] The command at ${filePath} is missing a required "data" property.`
|
||||
);
|
||||
|
@ -46,7 +47,8 @@ export const deployCommands = async () => {
|
|||
console.log(
|
||||
`Successfully reloaded ${data.length} application (/) commands.`
|
||||
);
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue