Skip to content

fix: Enforce name limit of 2 again for custom emojis#11375

Open
Jiralite wants to merge 2 commits intomainfrom
fix/emoji-predicate-custom-emoji-length
Open

fix: Enforce name limit of 2 again for custom emojis#11375
Jiralite wants to merge 2 commits intomainfrom
fix/emoji-predicate-custom-emoji-length

Conversation

@Jiralite
Copy link
Member

@Jiralite Jiralite commented Jan 2, 2026

Fixes a regression introduced with #11371 that allowed custom emojis to have a name of length 1.

Also fixes the dishonest emoji tests where a name was specified with a string instead of actual emojis.

@vercel
Copy link

vercel bot commented Jan 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
discord-js Skipped Skipped Jan 2, 2026 11:34am
discord-js-guide Skipped Skipped Jan 2, 2026 11:34am

@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.45%. Comparing base (7884ecd) to head (d762763).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11375      +/-   ##
==========================================
+ Coverage   32.43%   32.45%   +0.01%     
==========================================
  Files         369      369              
  Lines       13616    13620       +4     
  Branches     1068     1069       +1     
==========================================
+ Hits         4416     4420       +4     
  Misses       9065     9065              
  Partials      135      135              
Flag Coverage Δ
builders 67.96% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link

coderabbitai bot commented Jan 2, 2026

📝 Walkthrough

Walkthrough

Updates emoji test cases in button and select menu builders to use emoji character objects and adjust validation. Modifies emojiPredicate in Assertions.ts to enforce that custom emoji names must be at least 2 characters when both id and name fields are provided.

Changes

Cohort / File(s) Summary
Test emoji updates
packages/builders/__tests__/components/button.test.ts, packages/builders/__tests__/components/selectMenu.test.ts
Replaced emoji name strings with emoji characters and added test cases for emoji objects with id/name/animated fields. Adjusted expectations to include toJSON invocations after emoji assignments. Updated selectMenu option emoji from { name: 'test' } to { name: '🩵' }.
Emoji validation schema
packages/builders/src/components/Assertions.ts
Modified emojiPredicate: changed name constraint from min(1) to max(32), added period to refine error message. Added second refine enforcing minimum 2-character length for custom emoji names when both id and name are defined, with targeted error path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enforcing a 2-character minimum name limit for custom emojis to fix a regression.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description directly addresses the changeset by identifying the regression being fixed and explaining the validation constraint being re-enforced.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 311413e and 5dacf1a.

📒 Files selected for processing (3)
  • packages/builders/__tests__/components/button.test.ts
  • packages/builders/__tests__/components/selectMenu.test.ts
  • packages/builders/src/components/Assertions.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/builders/__tests__/components/button.test.ts (2)
packages/builders/src/components/button/CustomIdButton.ts (2)
  • PrimaryButtonBuilder (41-45)
  • DangerButtonBuilder (68-72)
packages/builders/src/components/button/LinkButton.ts (1)
  • LinkButtonBuilder (17-37)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Tests
  • GitHub Check: Tests
🔇 Additional comments (9)
packages/builders/__tests__/components/button.test.ts (6)

24-32: LGTM! Unicode emoji test correctly updated.

The test now uses an emoji character object { name: '🩵' } instead of a string, and the addition of button.toJSON() ensures the emoji validation is exercised during serialization. This aligns with the updated validation logic.


34-42: LGTM! Custom emoji validation test correctly added.

This test case properly validates custom emojis with both id and name fields. The name 'test' has 4 characters, which satisfies the new minimum length requirement of 2 characters for custom emoji names.


49-52: LGTM! Unicode emoji test updated correctly.

The test correctly uses an emoji character object for a unicode emoji on a danger button.


59-62: LGTM! Link button emoji test updated correctly.

The test correctly uses an emoji character object for a unicode emoji on a link button.


77-91: LGTM! Critical test case for custom emoji name length validation.

This test segment correctly validates the PR's main objective:

  • Line 79-81: Properly expects an error when passing an emoji string instead of an object
  • Line 88: Critically tests the new constraint - a custom emoji (with id) having a name of length 1 should throw an error, enforcing the minimum 2-character requirement for custom emoji names

109-109: LGTM! Invalid emoji format test.

Correctly expects an error when passing an emoji string instead of an object.

packages/builders/src/components/Assertions.ts (2)

11-13: LGTM! Improved error message for mandatory field validation.

The updated error message with proper punctuation improves readability. However, note that this refine only checks for undefined and doesn't prevent empty strings (see comment on line 8).


14-26: LGTM! Correctly enforces minimum name length for custom emojis.

This cross-field validation perfectly addresses the PR objective by enforcing that custom emojis (those with an id) must have names of at least 2 characters when the name field is provided. The validation logic is correct:

  • When both id and name are defined: enforces name.length >= 2
  • When only id OR only name is defined: validation passes (returns true)

This allows unicode emojis (no id) to have single-character names like { name: '🩵' } while preventing custom emojis from having single-character names like { id: '123', name: 'a' }.

packages/builders/__tests__/components/selectMenu.test.ts (1)

83-83: LGTM! Select menu emoji test updated consistently.

The change from { name: 'test' } to { name: '🩵' } aligns with the emoji handling updates across the test suite. This correctly tests unicode emoji usage in select menu options, consistent with the changes made to button tests.

@vercel vercel bot temporarily deployed to Preview – discord-js-guide January 2, 2026 11:34 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js January 2, 2026 11:34 Inactive
.setCustomId('custom')
.setLabel('test')
.setDisabled(true)
.setEmoji({ id: '1234567890123456', name: '1' });
Copy link
Member

Choose a reason for hiding this comment

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

For custom emojis, does discord actually validate their name? Because when sending a message, we can still do <:_:[id]> no?

Copy link
Contributor

Choose a reason for hiding this comment

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

They don't validate, but (some) clients viewing the emote will grab the name from cache.

Still, they are documented as 2-32 long in name, you cannot name them as single chars, and our previous hacky workaround of ignoring this and using _ would break markdown in places.

@almeidx
Copy link
Member

almeidx commented Jan 6, 2026

FYI the name field doesn't seem to be validated at all by the API for custom emojis. You can send numbers, booleans, empty strings, very large strings, or null. Seemingly anything but an object or an array

@Jiralite
Copy link
Member Author

Jiralite commented Jan 6, 2026

Did you try uploading an emoji?

{
    "message": "Invalid Form Body",
    "code": 50035,
    "errors": {
        "name": {
            "_errors": [
                {
                    "code": "BASE_TYPE_BAD_LENGTH",
                    "message": "Must be between 2 and 32 in length."
                }
            ]
        }
    }
}

@almeidx
Copy link
Member

almeidx commented Jan 6, 2026

I sent a primary button component with a custom emoji, which is one of the predicates this pull request is modifying

@Jiralite
Copy link
Member Author

Jiralite commented Jan 6, 2026

Right, and how did you get that custom emoji? It was uploaded somewhere.

@vladfrangu
Copy link
Member

@Jiralite i think they're referring to the API validating the emoji name when creating the message, not the emoji structure itself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants