Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
require('dotenv').config();
|
|
|
|
|
|
|
| 2 |
const { Client, GatewayIntentBits, Partials, Collection, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, UserSelectMenuBuilder, ChannelSelectMenuBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ComponentType, MessageFlags, ChannelType } = require('discord.js');
|
| 3 |
const storage = require('./storage');
|
| 4 |
const roleStorage = require('./roleStorage');
|
|
@@ -21,6 +23,23 @@ if (process.env.BYPASS_PROXY_FOR_DISCORD === 'true') {
|
|
| 21 |
|
| 22 |
// Keep startup networking simple and stable:
|
| 23 |
// no DNS hijack, no route rotation, no custom global dispatcher.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
console.log(`[SYSTEM] Starting FriendlyBot v4.0 (Watchdog Relaxed: ${new Date().toISOString()})`);
|
| 26 |
|
|
|
|
| 1 |
require('dotenv').config();
|
| 2 |
+
const dns = require('dns');
|
| 3 |
+
const { Agent, setGlobalDispatcher } = require('undici');
|
| 4 |
const { Client, GatewayIntentBits, Partials, Collection, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, UserSelectMenuBuilder, ChannelSelectMenuBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ComponentType, MessageFlags, ChannelType } = require('discord.js');
|
| 5 |
const storage = require('./storage');
|
| 6 |
const roleStorage = require('./roleStorage');
|
|
|
|
| 23 |
|
| 24 |
// Keep startup networking simple and stable:
|
| 25 |
// no DNS hijack, no route rotation, no custom global dispatcher.
|
| 26 |
+
// But do tune connection behavior for hosted environments:
|
| 27 |
+
// force IPv4 preference and allow longer connect timeout than 10s.
|
| 28 |
+
try {
|
| 29 |
+
if (dns.setDefaultResultOrder) dns.setDefaultResultOrder('ipv4first');
|
| 30 |
+
const transportAgent = new Agent({
|
| 31 |
+
connect: {
|
| 32 |
+
timeout: 30000,
|
| 33 |
+
family: 4
|
| 34 |
+
},
|
| 35 |
+
keepAliveTimeout: 60000,
|
| 36 |
+
pipelining: 1
|
| 37 |
+
});
|
| 38 |
+
setGlobalDispatcher(transportAgent);
|
| 39 |
+
console.log('[NETWORK] IPv4-first + 30s connect timeout enabled.');
|
| 40 |
+
} catch (e) {
|
| 41 |
+
console.warn('[NETWORK] Transport tuning skipped:', e.message || e);
|
| 42 |
+
}
|
| 43 |
|
| 44 |
console.log(`[SYSTEM] Starting FriendlyBot v4.0 (Watchdog Relaxed: ${new Date().toISOString()})`);
|
| 45 |
|