converted ShaiBot casino to Nut Economy

This commit is contained in:
2026-08-19 14:10:38 +02:00
parent a126de21d4
commit 1957991182
55 changed files with 8905 additions and 751 deletions
+208 -29
View File
@@ -1,33 +1,212 @@
const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js')
const { MongoClient } = require('mongodb')
require('dotenv').config()
const mClient = new MongoClient(process.env.M_URI)
exports.mClient = mClient;
const fs = require('node:fs')
const {
Client,
GatewayIntentBits,
Collection,
Partials
} = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
],
partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction]
});
exports.client = client
const {
MongoClient
} = require("mongodb");
client.commands = new Collection() // slash commands collection
client.legacyCommands = new Collection() // legacy commands collection
client.aliases = new Collection() // list of command aliases
client.buttons = new Collection() // list of buttons
client.selectMenus = new Collection() // list of selectMenus
const fs =
require("node:fs");
fs.readdirSync('./handlers').forEach((handler) => {
require(`./handlers/${handler}`)(client)
});
require("dotenv").config();
client.login(process.env.D_Token)
/*
* ============================================================
* MONGODB
* ============================================================
*/
const mClient =
new MongoClient(
process.env.M_URI
);
/*
* Export this BEFORE handlers/commands are loaded.
*
* utils/nutEconomy.js imports mClient from index.js.
*/
exports.mClient =
mClient;
/*
* ============================================================
* DISCORD CLIENT
* ============================================================
*/
const client =
new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel,
Partials.Message,
Partials.User,
Partials.GuildMember,
Partials.Reaction
]
});
exports.client =
client;
/*
* ============================================================
* COLLECTIONS
* ============================================================
*/
client.commands =
new Collection();
client.legacyCommands =
new Collection();
client.aliases =
new Collection();
client.buttons =
new Collection();
client.selectMenus =
new Collection();
/*
* ============================================================
* STARTUP
* ============================================================
*/
async function start() {
try {
/*
* Connect Mongo first.
*/
await mClient.connect();
console.log(
"[MongoDB] Connected"
);
/*
* Load handlers only after MongoDB is ready.
*/
const handlers =
fs.readdirSync(
"./handlers"
);
for (
const handler
of handlers
) {
require(
`./handlers/${handler}`
)(
client
);
}
/*
* Finally connect to Discord.
*/
await client.login(
process.env.D_Token
);
} catch (error) {
console.error(
"Failed to start bot:",
error
);
process.exit(
1
);
}
}
/*
* ============================================================
* SHUTDOWN
* ============================================================
*/
async function shutdown(
signal
) {
console.log(
`[System] ${signal} received, shutting down...`
);
try {
client.destroy();
} catch {}
try {
await mClient.close();
} catch {}
process.exit(
0
);
}
process.on(
"SIGINT",
() =>
shutdown(
"SIGINT"
)
);
process.on(
"SIGTERM",
() =>
shutdown(
"SIGTERM"
)
);
/*
* ============================================================
* START
* ============================================================
*/
start();