Skip to content

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

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
wants to merge 3 commits into
base: V3/develop
Choose a base branch
from

Conversation

AAA3A-AAA3A
Copy link
Contributor

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

@github-actions github-actions bot added the Category: Core - API - Utils Package This is related to stuff in `redbot.core.utils` label Jul 15, 2025
@Flame442
Copy link
Member

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.

@Flame442 Flame442 added the Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. label Jul 15, 2025
@Flame442 Flame442 added this to the 3.5.21 milestone Jul 15, 2025
@AAA3A-AAA3A
Copy link
Contributor Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Core - API - Utils Package This is related to stuff in `redbot.core.utils` Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants