fix async imports#220
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restructures how the Discord client and event handlers are imported/initialized to avoid async/circular-import timing issues (notably under Bun), while also standardizing command replies via a shared embed helper and adjusting YouTube upload-type detection.
Changes:
- Introduces a shared
src/client.tsand updates imports across events/utils/commands to use it instead of importing from index/root. - Ensures events are imported/registered before
client.login()so interaction handlers are attached in time. - Refactors command replies to use a reusable quick-embed helper and updates YouTube upload classification to use duration + playlist checks.
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/youtube/sendLatestUploads.ts | Updates client import path to the new shared client module. |
| src/utils/youtube/fetchLatestUploads.ts | Adds duration-based classification + new YouTube Videos API response typing. |
| src/utils/twitch/checkIfStreamerIsLive.ts | Updates client import path to the new shared client module. |
| src/utils/quickEmbed.ts | Adds reusable embed builder + interaction reply helper utilities. |
| src/utils/discord/updateGuildsOnStartup.ts | Updates client import path to the new shared client module. |
| src/utils/cronJobs.ts | Updates client import path to the new shared client module. |
| src/types/youtube.d.ts | Adds typing for YouTube Videos API contentDetails response. |
| src/index.ts | Imports events before login and uses the shared client module. |
| src/events/ready.ts | Updates client import path to the new shared client module. |
| src/events/guildDelete.ts | Updates client import path to the new shared client module. |
| src/events/guildCreate.ts | Updates client import path to the new shared client module. |
| src/events/commandHandlerAuto.ts | Updates client import path to the new shared client module. |
| src/events/commandHandler.ts | Updates client import path to the new shared client module. |
| src/commands.ts | Switches many replies to replyWithQuickEmbed and updates client import path. |
| src/client.ts | New shared Discord Client instance module. |
| package.json | Updates start script and dependency versions/formatting. |
| bun.lock | Lockfile updates reflecting dependency version changes. |
Comments suppressed due to low confidence (1)
src/utils/youtube/fetchLatestUploads.ts:195
- shortVideoId.videoId and/or streamVideoId.videoId may be null (API error/empty playlist). The current logic will fall through and classify the upload as a regular video, which can update the DB with the wrong contentType and cause missed notifications for shorts/streams. Guard against null results and skip updating when both lookups fail.
const [shortVideoId, streamVideoId] = await Promise.all([
getSinglePlaylistAndReturnVideoData(
channelId,
PlaylistType.Short,
),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+177
to
+181
| const streamVideoId = | ||
| await getSinglePlaylistAndReturnVideoData( | ||
| channelId, | ||
| PlaylistType.Stream, | ||
| ); |
Owner
Author
There was a problem hiding this comment.
idk, works as intended when i run it, gotta check in a few days
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bun, at some point, broke the way that imports worked for the bot - however my other bots work fine with the same codebase so idk anymore.
Anyway, this resolves #219 i think?