Update the invite Regex pattern with a new accepted format. #6586

Merged
AAA3A-AAA3A merged 3 commits from patch-3 into V3/develop 2025-09-04 16:49:49 +02:00
AAA3A-AAA3A commented 2025-07-16 01:01:55 +02:00 (Migrated from github.com)

Description of the changes

Hello,
Last week we noticed on several servers where I'm staff that a new invite format is displayed by Discord as valid but is not currently supported by most bots, leaving the door open to scam bots. The new format is discordapp.com/invite\<code>.
image
I'm using this modified pattern in one of my cogs, while waiting for a modification in Red.
Thanks in advance,
Have a nice day,
AAA3A

Have the changes in this PR been tested?

Yes

### Description of the changes Hello, Last week we noticed on several servers where I'm staff that a new invite format is displayed by Discord as valid but is not currently supported by most bots, leaving the door open to scam bots. The new format is `discordapp.com/invite\<code>`. <img width="741" height="712" alt="image" src="https://github.com/user-attachments/assets/58f524dd-2a5f-4813-a649-0ae64682ec6f" /> I'm using this modified pattern in one of my cogs, while waiting for a modification in Red. Thanks in advance, Have a nice day, AAA3A ### Have the changes in this PR been tested? <!-- Choose one (remove the line that doesn't apply): --> Yes <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
Flame442 commented 2025-07-16 01:32:42 +02:00 (Migrated from github.com)

This isn't really a "new" format, it is a byproduct of the fact that chrome (and chromium based browsers, like the discord client) assume backslash characters are typo'd forwards slash characters. Maybe this became a "workaround" recently due to invite links embeding even when not a clickable URL... Technically any of the slashes could be backslashes and still be a valid URL for a chromium based browser, though only some cases actually render the invite embed in the discord client.

Any of the following will trigger the embed:
discord.com/invite\red
discordapp.com/invite\red
https://discord.gg\red (visually appears with a forward slash since the link is clickable)

But these will not trigger the embed:
discord.gg\red on its own without https://
discord.com\invite/red
discordapp.com\invite/red

Interestingly, putting backslashes in https:\\ does not cause the link to become clickable or for the invite embed to appear, despite chromium based browsers accepting it as a valid URL.

I wouldn't trust any of this behavior to never change again. The safest thing to do is probably to union every slash in both the invite URL and the link URL regexs to match either a forward or a backslash, since either way someone is clearly trying to advertise, even if an embed doesn't appear.

This isn't really a "new" format, it is a byproduct of the fact that chrome (and chromium based browsers, like the discord client) assume backslash characters are typo'd forwards slash characters. Maybe this became a "workaround" recently due to invite links embeding even when not a clickable URL... Technically any of the slashes could be backslashes and still be a valid URL for a chromium based browser, though only some cases actually render the invite embed in the discord client. Any of the following will trigger the embed: `discord.com/invite\red` `discordapp.com/invite\red` `https://discord.gg\red` (visually appears with a forward slash since the link is clickable) But these will not trigger the embed: `discord.gg\red` on its own without `https://` `discord.com\invite/red` `discordapp.com\invite/red` Interestingly, putting backslashes in `https:\\` does not cause the link to become clickable or for the invite embed to appear, despite chromium based browsers accepting it as a valid URL. I wouldn't trust any of this behavior to never change again. The safest thing to do is probably to union every slash in both the invite URL and the link URL regexs to match either a forward or a backslash, since either way someone is clearly trying to advertise, even if an embed doesn't appear.
AAA3A-AAA3A commented 2025-07-16 01:59:26 +02:00 (Migrated from github.com)

Yes, it's not a "new" format, but it's something that has been detected by Discord as an invite since very recently and that some scams are starting to use.
Would you like me to add the union for each slash, and to the other pattern as well?

Yes, it's not a "new" format, but it's something that has been detected by Discord as an invite since very recently and that some scams are starting to use. Would you like me to add the union for each slash, and to the other pattern as well?
Twentysix26 commented 2025-07-19 15:22:35 +02:00 (Migrated from github.com)

It's probably a good time to mention that this regex also catches promos.discord.gg links, which are not server invites (https://github.com/Twentysix26/x26-Cogs/issues/57)
This could be solved with a negative lookbehind, which should result in
(?<!promos\.)(discord\.(?:gg|io|me|li)|discord(?:app)?\.com\/invite)[\/\\](\S+)

It's probably a good time to mention that this regex also catches `promos.discord.gg` links, which are not server invites (https://github.com/Twentysix26/x26-Cogs/issues/57) This could be solved with a negative lookbehind, which should result in `(?<!promos\.)(discord\.(?:gg|io|me|li)|discord(?:app)?\.com\/invite)[\/\\](\S+)`
Jackenmen (Migrated from github.com) approved these changes 2025-09-04 16:49:09 +02:00
Jackenmen (Migrated from github.com) left a comment

Thanks!

Thanks!
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6586
No description provided.