Skip to content

Conversation

@Rutherther
Copy link
Contributor

Hey, a user of my bot tried to use a link in a command. It wasn't working and it causes bit of a confusion as the mention looks the same a sent link in the client. I will use this in my bot if it won't be accepted here for sure, but wanted to check with you here for feedback / to merge this to Remora.Discord directly if others will appreciate this behavior as well. I can add more validation if needed, ie. to check if there are only 2 or 3 parts after the url (guild, channel, message), and to check if they consist of all numbers if you think that is necessary. But I don't see any risks if wrong links, such as https://discord.com/channels/XYZ/XYZ/XYZ/XYZ/ are accepted.

If user sends a link to a channel, it's not being parsed by Remora. On the other hand the client understands this link and visually there is no difference between a mention and a channel link.

Add parsing of a channel links, without checking the whole string, only beginning 'https://discord.com/channels/' is used to check this is a url, and only the last part of the string is then used, all other parts are ignored.

@Rutherther Rutherther force-pushed the feat/snowflake-parse-url branch from 6dbef75 to 0785c79 Compare July 1, 2025 14:31
@VelvetToroyashi
Copy link
Contributor

The parser should also handle the subdomains of other client versions (ptb, canary) if this is to be accepted, imo

e.g., I use canary, and thus message and channel links are https://canary.discord.com/channels/123/

@Rutherther
Copy link
Contributor Author

Hm, I had no idea that is a thing. How do you obtain such urls though? The one I used in the parser is obtained by right clicking and copying a link

@Rutherther Rutherther force-pushed the feat/snowflake-parse-url branch from 0785c79 to 95fedea Compare July 1, 2025 14:42
@VelvetToroyashi
Copy link
Contributor

By using Discord's beta clients (e.g. for Windows ); ptb is available via the webpage; both can be used in the browser by just prepending ptb or canary to discord.com.

@Rutherther
Copy link
Contributor Author

If such urls are to be allowed, I will switch to regex matching with a group, and also check for only numbers, as at that point, it doesn't really matter. I didn't do it just because I haven't used regex for this simple case.

@Rutherther
Copy link
Contributor Author

By using Discord's beta clients (e.g. for Windows ); ptb is available via the webpage; both can be used in the browser by just prepending ptb or canary to discord.com.

Oh you mean like if you copy the url from the bar, right

@VelvetToroyashi
Copy link
Contributor

VelvetToroyashi commented Jul 1, 2025

No; the beta clients give links that match; e.g. https://canary.discord.com/channels/789912892426027039/789924168837365810/1389617555861143764

edit: I meant that PTB (Public Test Beta) can be downloaded via Discord's website

@Rutherther
Copy link
Contributor Author

Give... how?

@VelvetToroyashi
Copy link
Contributor

VelvetToroyashi commented Jul 1, 2025

Right clicking a message like normal

Discord -> discord.com/channels
Discord PTB -> ptb.discord.com/channels
Discord Canary -> canary.discord.com/channels

Same goes for all links that can be acquired copied in the client, save for media links

@Rutherther
Copy link
Contributor Author

So Copy link button okay. I also see Discord parses all of them, so I agree with your proposal. I will probably not be able to make it today, though.

@Rutherther Rutherther marked this pull request as draft July 1, 2025 14:48
@Rutherther Rutherther force-pushed the feat/snowflake-parse-url branch from 95fedea to 7c20456 Compare July 2, 2025 11:36
@Rutherther
Copy link
Contributor Author

So, as proposed, I added ptb and canary support. I used regex from MessageParser and changed it a little. I made message id optional, and also changed * with + for the individual snowflake parts of the url. Tbh I don't understand why messageparser uses * instead of +, it seems to me that https://discord.com/// would match... But I haven't tried it yet. Let me know what you think.

public override ValueTask<Result<Snowflake>> TryParseAsync(string value, CancellationToken ct = default)
{
var channelLinkMatch = _channelLinkRegex.Match(value);
if (channelLinkMatch.Success)

Check warning

Code scanning / InspectCode

Invert 'if' statement to reduce nesting Warning

Invert 'if' statement to reduce nesting
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this tbh.

If user sends a link to a channel, it's not being parsed by Remora. On
the other hand the client understands this link and visually there is
no difference between a mention and a channel link.

Add parsing of a channel links, without checking the whole string,
only beginning 'https://discord.com/channels/' is used to check this
is a url, and only the last part of the string is then used, all other
parts are ignored.
@Rutherther Rutherther force-pushed the feat/snowflake-parse-url branch from 7c20456 to b36653b Compare July 2, 2025 14:25
@Rutherther Rutherther marked this pull request as ready for review July 14, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants