Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
contents: write
jobs:
create-release:
if: github.event.pull_request.merged == true
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-features-handler",
"version": "3.2.0",
"version": "3.2.1",
"description": "An simple discord regular and slash commands, events and modules handler with folder structure",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
37 changes: 31 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,37 @@ const DiscordFeaturesHandler = async (
client.levelCache[thisLevel.name.toString()] = thisLevel.level;
}

client.login(client.config.token).catch((e) => {
console.warn(e);
throw new Error(
`Please check if your discord bot token is valid! The token should be defined in config.token`
);
});
const loginWithRetry = async (client, maxRetries = 3) => {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
await client.login(client.config.token);
return;
} catch (error) {
console.warn(`Login attempt ${attempt} failed:`, error.message);

if (error.code === "TOKEN_INVALID" || error.message.includes("401")) {
throw new Error(
"Invalid token provided. Please check your discord bot token in config.token"
);
}

if (attempt === maxRetries) {
throw new Error(
`Failed to login after ${maxRetries} attempts. Last error: ${error.message}`
);
}

const baseDelay = 1000;
const jitter = Math.random() * 500;
const delay = baseDelay * Math.pow(2, attempt - 1) + jitter;

console.log(`Retrying in ${Math.round(delay)}ms...`);
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
};

await loginWithRetry(client);
await client.wait(modulesPreloadTime);

loadModules({
Expand Down