Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 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');
|
|
@@ -27,16 +27,22 @@ if (process.env.BYPASS_PROXY_FOR_DISCORD === 'true') {
|
|
| 27 |
// force IPv4 preference and allow longer connect timeout than 10s.
|
| 28 |
try {
|
| 29 |
if (dns.setDefaultResultOrder) dns.setDefaultResultOrder('ipv4first');
|
| 30 |
-
const
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
} catch (e) {
|
| 41 |
console.warn('[NETWORK] Transport tuning skipped:', e.message || e);
|
| 42 |
}
|
|
@@ -63,10 +69,10 @@ const client = new Client({
|
|
| 63 |
rest: {
|
| 64 |
api: 'https://discord.com/api',
|
| 65 |
version: '10',
|
| 66 |
-
timeout:
|
| 67 |
},
|
| 68 |
ws: {
|
| 69 |
-
connectTimeout:
|
| 70 |
}
|
| 71 |
});
|
| 72 |
|
|
|
|
| 1 |
require('dotenv').config();
|
| 2 |
const dns = require('dns');
|
| 3 |
+
const { Agent, ProxyAgent, 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');
|
|
|
|
| 27 |
// force IPv4 preference and allow longer connect timeout than 10s.
|
| 28 |
try {
|
| 29 |
if (dns.setDefaultResultOrder) dns.setDefaultResultOrder('ipv4first');
|
| 30 |
+
const discordProxyUrl = process.env.DISCORD_PROXY_URL || '';
|
| 31 |
+
if (discordProxyUrl) {
|
| 32 |
+
setGlobalDispatcher(new ProxyAgent(discordProxyUrl));
|
| 33 |
+
console.log('[NETWORK] Using DISCORD_PROXY_URL transport.');
|
| 34 |
+
} else {
|
| 35 |
+
const transportAgent = new Agent({
|
| 36 |
+
connect: {
|
| 37 |
+
timeout: 30000,
|
| 38 |
+
family: 4
|
| 39 |
+
},
|
| 40 |
+
keepAliveTimeout: 60000,
|
| 41 |
+
pipelining: 1
|
| 42 |
+
});
|
| 43 |
+
setGlobalDispatcher(transportAgent);
|
| 44 |
+
console.log('[NETWORK] IPv4-first + 30s connect timeout enabled.');
|
| 45 |
+
}
|
| 46 |
} catch (e) {
|
| 47 |
console.warn('[NETWORK] Transport tuning skipped:', e.message || e);
|
| 48 |
}
|
|
|
|
| 69 |
rest: {
|
| 70 |
api: 'https://discord.com/api',
|
| 71 |
version: '10',
|
| 72 |
+
timeout: 120000
|
| 73 |
},
|
| 74 |
ws: {
|
| 75 |
+
connectTimeout: 120000
|
| 76 |
}
|
| 77 |
});
|
| 78 |
|