Download src/index.js from APRKDEV/wsb-bot: direct link, hf CLI and curl.
- Browser
- Download file 3.77 kB
-
https://huggingface.co/spaces/APRKDEV/wsb-bot/resolve/c8f3880098432483b23491dd763585274d00f8c8/src/index.js
- Command line
-
hf download hf://spaces/APRKDEV/wsb-bot@c8f3880098432483b23491dd763585274d00f8c8/src/index.js
-
curl -L -o index.js https://huggingface.co/spaces/APRKDEV/wsb-bot/resolve/c8f3880098432483b23491dd763585274d00f8c8/src/index.js
3.77 kB
| require('dotenv').config(); | |
| const { | |
| Client, | |
| GatewayIntentBits, | |
| Partials, | |
| } = require('discord.js'); | |
| // ββ Validate Environment ββββββββββββββββββββββββββββββββββββββ | |
| const required = ['BOT_TOKEN', 'OWNER_ID', 'GUILD_ID']; | |
| console.log(' π ENV CHECK:', required.map(k => `${k}=${process.env[k] ? 'β ' : 'β'}`).join(' | ')); | |
| for (const key of required) { | |
| if (!process.env[key] || process.env[key].includes('YOUR_')) { | |
| console.error(`β Missing or placeholder env var: ${key}`); | |
| console.error(' Please fill in your .env file before starting.'); | |
| process.exit(1); | |
| } | |
| } | |
| // ββ Create Client βββββββββββββββββββββββββββββββββββββββββββββ | |
| const client = new Client({ | |
| intents: [ | |
| GatewayIntentBits.Guilds, | |
| GatewayIntentBits.GuildMembers, | |
| GatewayIntentBits.GuildMessages, | |
| GatewayIntentBits.GuildMessageReactions, | |
| GatewayIntentBits.DirectMessages, | |
| GatewayIntentBits.MessageContent, | |
| GatewayIntentBits.GuildPresences, | |
| ], | |
| partials: [ | |
| Partials.Message, | |
| Partials.Channel, | |
| Partials.Reaction, | |
| Partials.User, | |
| Partials.GuildMember, | |
| ], | |
| }); | |
| // ββ Load Event Handlers βββββββββββββββββββββββββββββββββββββββ | |
| const events = [ | |
| require('./events/ready'), | |
| require('./events/messageCreate'), | |
| require('./events/messageReactionAdd'), | |
| require('./events/messageReactionRemove'), | |
| require('./events/guildMemberUpdate'), | |
| require('./events/guildMemberAdd'), | |
| require('./events/guildMemberRemove'), | |
| require('./events/interactionCreate'), | |
| ]; | |
| for (const event of events) { | |
| if (event.once) { | |
| client.once(event.name, (...args) => event.execute(client, ...args)); | |
| } else { | |
| client.on(event.name, (...args) => event.execute(client, ...args)); | |
| } | |
| } | |
| // ββ Error Handling ββββββββββββββββββββββββββββββββββββββββββββ | |
| client.on('error', (err) => { | |
| console.error('[Client Error]', err); | |
| }); | |
| process.on('unhandledRejection', (err) => { | |
| console.error('[Unhandled Rejection]', err); | |
| }); | |
| process.on('uncaughtException', (err) => { | |
| console.error('[Uncaught Exception]', err); | |
| process.exit(1); | |
| }); | |
| // ββ Keep-Alive HTTP Server (for Render / Glitch + UptimeRobot) β | |
| const http = require('http'); | |
| const PORT = process.env.PORT || 3000; | |
| http.createServer((req, res) => { | |
| res.writeHead(200, { 'Content-Type': 'application/json' }); | |
| res.end(JSON.stringify({ | |
| status: 'alive', | |
| bot: client.user?.tag || 'starting...', | |
| uptime: Math.floor(process.uptime()) + 's', | |
| })); | |
| }).listen(PORT, () => { | |
| console.log(` π Keep-alive server on port ${PORT}`); | |
| }); | |
| // ββ Login βββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| const token = process.env.BOT_TOKEN; | |
| console.log(` π Token: ${token ? token.slice(0, 10) + '...' + token.slice(-5) : 'MISSING'}`); | |
| console.log(' β³ Connecting to Discord...'); | |
| const loginTimeout = setTimeout(() => { | |
| console.error('β LOGIN TIMED OUT after 30s β Discord gateway unreachable'); | |
| }, 30000); | |
| client.login(token).then(() => { | |
| clearTimeout(loginTimeout); | |
| console.log(' β Login promise resolved'); | |
| }).catch(err => { | |
| clearTimeout(loginTimeout); | |
| console.error('β LOGIN FAILED:', err.message); | |
| process.exit(1); | |
| }); | |