-
Notifications
You must be signed in to change notification settings - Fork 1.5k
domain-skills: add Discord channel scraping #545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexandme
wants to merge
1
commit into
browser-use:main
Choose a base branch
from
alexandme:domain-skill/discord-scraping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Discord — channel scraping | ||
|
|
||
| Read full message history from a Discord channel in the logged-in web app. No API token needed — this drives the user's authenticated session. Channel access requires the account to be a member of the server. | ||
|
|
||
| ## URL pattern | ||
|
|
||
| ``` | ||
| https://discord.com/channels/<guildId>/<channelId> | ||
| ``` | ||
|
|
||
| Tab title shows unread count + channel name: `🟢 (224) Discord | #channel-name | ServerName`. | ||
|
|
||
| ## Site structure | ||
|
|
||
| - React app, fully virtualized message list — only the messages near the viewport exist in the DOM. To read history you must scroll up in a loop and merge. | ||
| - Message list: `ol[data-list-id="chat-messages"]`, items `li[id^="chat-messages-"]`. | ||
| - Item id format: `chat-messages-<channelId>-<messageId>`. The message id is a snowflake — sort on it for chronological order across merged batches. | ||
| - Scroll container: `main div[class*="scroller_"]`. Set `scrollTop = 0` to trigger loading older messages; wait ~1.5s for the lazy fetch, then re-extract. | ||
| - Start-of-channel marker: the scroller's top renders "Welcome to #channel!" / "This is the start of the … channel." Test the scroller's leading `innerText` for `/Welcome to|This is the (start|beginning) of/`. Stop when the marker is present AND an extract pass yields no new ids. | ||
| - Timestamps: `time[datetime]` inside the item — absolute ISO, no parsing of "Yesterday at…" needed. | ||
| - Embeds (link previews, tweets, GitHub cards): `article` elements; `innerText` gives a usable text rendering. | ||
| - Reactions: `div[class*="reaction"] img` — `alt` holds the emoji or custom-emoji name. | ||
|
|
||
| ## Traps | ||
|
|
||
| - **Reply previews duplicate the content id.** A reply message contains the quoted preview of the parent, and that preview div ALSO matches `div[id^="message-content-"]`. `querySelector` returns the preview, so you silently scrape the quoted text instead of the actual reply body. Select all matches and keep the one not inside `div[class*="repliedMessage"]`: | ||
|
|
||
| ```js | ||
| const contentEl = [...li.querySelectorAll('div[id^="message-content-"]')] | ||
| .find(el => !el.closest('div[class*="repliedMessage"]')); | ||
| ``` | ||
|
|
||
| - **Grouped messages have no author node.** Consecutive messages from the same author within ~7 minutes render without the `h3` header. Author selector `h3 span[class*="username"]` returns null for them — forward-fill from the previous message after sorting. | ||
| - **`h3` innerText is polluted.** Grabbing the whole `h3` text concatenates username + server tag + timestamp tooltip ("kaue [STBR], Server Tag: STBR — 7/17/26…"). Use the `span[class*="username"]` child only. | ||
| - **Edited messages append the edit tooltip** ("(edited)\nSunday, July 19 …") to `innerText` of the content div. Strip trailing date lines if exact text matters. | ||
| - Message links include internal `https://discord.com/channels/...` jump links — filter them if you only want external references. | ||
|
|
||
| ## Extraction loop shape | ||
|
|
||
| Per pass: collect `{id, author, time, text, replyTo, links, embeds, reactions}` for every `li`, merge into a dict keyed by id, scroll top, sleep ~1.5s, repeat until start marker + zero new ids. A ~25-message channel takes 2–3 passes at a full-height viewport. | ||
|
|
||
| ## Pinned messages | ||
|
|
||
| Open with `document.querySelector('[aria-label*="Pin"]').click()`; the popout is `div[class*="messagesPopout"]` — read its `innerText`. Empty state renders "This channel doesn't have any pinned messages... yet." | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The documented extraction shape can emit every reply without its parent relationship because
replyTohas no selector or extraction step, while the only reply-specific node is discarded for text extraction. Capturing the parent id from therepliedMessagepreview before excluding it would make the advertised field usable.Prompt for AI agents