fix: Adjust label predicates and fix buttons emoji/label behaviour (#11317)

* fix: buttons with custom id

* fix: button labels

* fix: also add refinement to link buttons

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2025-11-30 16:17:50 +00:00
committed by GitHub
parent d59857e901
commit ace834b274
3 changed files with 59 additions and 22 deletions

View File

@@ -5,7 +5,13 @@ import {
type APIButtonComponentWithURL,
} from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import { PrimaryButtonBuilder, PremiumButtonBuilder, LinkButtonBuilder } from '../../src/index.js';
import {
PrimaryButtonBuilder,
PremiumButtonBuilder,
LinkButtonBuilder,
DangerButtonBuilder,
SecondaryButtonBuilder,
} from '../../src/index.js';
const longStr =
'looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong';
@@ -25,6 +31,26 @@ describe('Button Components', () => {
button.toJSON();
}).not.toThrowError();
expect(() => {
const button = new SecondaryButtonBuilder().setCustomId('custom').setLabel('a'.repeat(80));
button.toJSON();
}).not.toThrowError();
expect(() => {
const button = new DangerButtonBuilder().setCustomId('custom').setEmoji({ name: 'ok' });
button.toJSON();
}).not.toThrowError();
expect(() => {
const button = new LinkButtonBuilder().setURL('https://discord.js.org').setLabel('a'.repeat(80));
button.toJSON();
}).not.toThrowError();
expect(() => {
const button = new LinkButtonBuilder().setURL('https://discord.js.org').setEmoji({ name: 'ok' });
button.toJSON();
}).not.toThrowError();
expect(() => {
const button = new PremiumButtonBuilder().setSKUId('123456789012345678');
button.toJSON();

View File

@@ -7,6 +7,9 @@ const selectMenuWithId = () => new StringSelectMenuBuilder({ custom_id: 'hi' });
const selectMenuOption = () => new StringSelectMenuOptionBuilder();
const longStr = 'a'.repeat(256);
const selectMenuOptionLabelAboveLimit = 'a'.repeat(101);
const selectMenuOptionValueAboveLimit = 'a'.repeat(101);
const selectMenuOptionDescriptionAboveLimit = 'a'.repeat(101);
const selectMenuOptionData: APISelectMenuOption = {
label: 'test',
@@ -196,13 +199,13 @@ describe('Select Menu Components', () => {
expect(() => {
selectMenuOption()
.setLabel(longStr)
.setValue(longStr)
.setLabel(selectMenuOptionLabelAboveLimit)
.setValue(selectMenuOptionValueAboveLimit)
// @ts-expect-error: Invalid default value
.setDefault(-1)
// @ts-expect-error: Invalid emoji
.setEmoji({ name: 1 })
.setDescription(longStr)
.setDescription(selectMenuOptionDescriptionAboveLimit)
.toJSON();
}).toThrowError();
});