Compare commits

...

7 Commits

Author SHA1 Message Date
Jiralite
4476fadd19 chore(builders): release @discordjs/builders@1.13.1 2025-11-30 19:35:11 +00:00
Jiralite
61251cfcb8 fix: Adjust label predicates (#11318)
* fix: labels in 14

* test: add variable for at limit

* docs(jsonOptionValidator): deprecate

* fix: export `selectMenuStringOptionPredicate`

* fix: export everything

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>

---------

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
2025-11-30 18:38:46 +00:00
Jiralite
e77793898a docs(Container): update example usage
Resolves #11297.
2025-11-28 10:24:58 +00:00
Jiralite
f5b3f842e3 fix(DJSError): Differentiate error type (#11295)
* fix(DJSError): differentiate error type

* fix: remove `?.`
2025-11-22 20:23:09 +00:00
Jiralite
e32f0c141a refactor(DJSError): Prefer this.constructor.name (#11294)
refactor(DJSError): prefer `this.constructor.name`
2025-11-22 12:50:54 +00:00
Jiralite
fdac8c5bdd chore(discord.js): release discord.js@14.25.1 2025-11-21 16:23:04 +00:00
Jiralite
0d64ea0528 fix(GuildEmojiManager): Allow CreateGuildExpressions for retrieving author data (#11288)
* fix(GuildEmojiManager)!: Allow `CreateGuildExpressions` for retrieving author data (#11283)

* fix(GuildEmojiManager): allow `CreateGuildExpressions`

* fix: tests
2025-11-21 16:22:20 +00:00
13 changed files with 48 additions and 18 deletions

View File

@@ -2,6 +2,16 @@
All notable changes to this project will be documented in this file.
# [@discordjs/builders@1.13.1](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.13.0...@discordjs/builders@1.13.1) - (2025-11-30)
## Bug Fixes
- Adjust label predicates (#11318) ([61251cf](https://github.com/discordjs/discord.js/commit/61251cfcb842cc468aca7a581f54be4fd28c2721))
## Documentation
- **Container:** Update example usage ([e777938](https://github.com/discordjs/discord.js/commit/e77793898ac36320eeee8b999c618918526ab9c2))
# [@discordjs/builders@1.13.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.12.2...@discordjs/builders@1.13.0) - (2025-10-24)
## Features

View File

@@ -6,6 +6,10 @@ const selectMenu = () => new StringSelectMenuBuilder();
const selectMenuOption = () => new StringSelectMenuOptionBuilder();
const longStr = 'a'.repeat(256);
const selectMenuOptionLabelAtLimit = 'a'.repeat(100);
const selectMenuOptionLabelAboveLimit = 'a'.repeat(101);
const selectMenuOptionValueAboveLimit = 'a'.repeat(101);
const selectMenuOptionDescriptionAboveLimit = 'a'.repeat(101);
const selectMenuOptionData: APISelectMenuOption = {
label: 'test',
@@ -53,12 +57,12 @@ describe('Select Menu Components', () => {
expect(() => selectMenu().setDisabled()).not.toThrowError();
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();
const option = selectMenuOption()
.setLabel('test')
.setLabel(selectMenuOptionLabelAtLimit)
.setValue('test')
.setDefault(true)
.setEmoji({ name: 'test' })
.setDescription('description');
expect(() => selectMenu().addOptions(option)).not.toThrowError();
expect(() => selectMenu().setCustomId('customId').addOptions(option).toJSON()).not.toThrowError();
expect(() => selectMenu().setOptions(option)).not.toThrowError();
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
expect(() => selectMenu().addOptions([option])).not.toThrowError();
@@ -156,13 +160,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);
}).toThrowError();
});

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/builders",
"version": "1.13.0",
"version": "1.13.1",
"description": "A set of builders that you can use when creating your bot",
"scripts": {
"test": "vitest run",

View File

@@ -50,6 +50,9 @@ export const labelValueDescriptionValidator = s
.lengthLessThanOrEqual(100)
.setValidationEnabled(isValidationEnabled);
/**
* @deprecated Replaced with selectMenuStringOptionPredicate.
*/
export const jsonOptionValidator = s
.object({
label: labelValueDescriptionValidator,

View File

@@ -2,7 +2,6 @@ import { Result, s } from '@sapphire/shapeshift';
import { ChannelType, ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10';
import { isValidationEnabled } from '../../util/validation.js';
import { customIdValidator, emojiValidator, idValidator } from '../Assertions.js';
import { labelValidator } from '../textInput/Assertions.js';
const selectMenuBasePredicate = s.object({
id: idValidator.optional(),
@@ -63,7 +62,7 @@ export const selectMenuUserPredicate = selectMenuBasePredicate
export const selectMenuStringOptionPredicate = s
.object({
label: labelValidator,
label: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
value: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
description: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).optional(),
emoji: emojiValidator.optional(),

View File

@@ -1,7 +1,8 @@
import { ComponentType } from 'discord-api-types/v10';
import type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
import { jsonOptionValidator, optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';
import { optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';
import { selectMenuStringOptionPredicate } from './Assertions.js';
import { BaseSelectMenuBuilder } from './BaseSelectMenu.js';
import { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js';
@@ -63,7 +64,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
...normalizedOptions.map((normalizedOption) =>
normalizedOption instanceof StringSelectMenuOptionBuilder
? normalizedOption
: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),
: new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)),
),
);
return this;
@@ -120,7 +121,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
...normalizedOptions.map((normalizedOption) =>
normalizedOption instanceof StringSelectMenuOptionBuilder
? normalizedOption
: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),
: new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)),
),
);

View File

@@ -71,7 +71,8 @@ export class ContainerBuilder extends ComponentBuilder<APIContainerComponent> {
* },
* ],
* })
* .addComponents(separator, section);
* .addSeparatorComponents(separator)
* .addSectionComponents(section);
* ```
*/
public constructor({ components, ...data }: Partial<APIContainerComponent> = {}) {

View File

@@ -31,6 +31,7 @@ export {
*/
StringSelectMenuOptionBuilder as SelectMenuOptionBuilder,
} from './components/selectMenu/StringSelectMenuOption.js';
export * as SelectMenuAssertions from './components/selectMenu/Assertions.js';
export * from './components/selectMenu/StringSelectMenuOption.js';
export * from './components/selectMenu/UserSelectMenu.js';

View File

@@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
# [14.25.1](https://github.com/discordjs/discord.js/compare/14.25.0...14.25.1) - (2025-11-21)
## Bug Fixes
- **GuildEmojiManager:** Allow `CreateGuildExpressions` for retrieving author data (#11288) ([0d64ea0](https://github.com/discordjs/discord.js/commit/0d64ea0528b1591ef9b856b9bcad52e88e2cbd05))
# [14.25.0](https://github.com/discordjs/discord.js/compare/14.24.2...14.25.0) - (2025-11-18)
## Bug Fixes

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "discord.js",
"version": "14.25.0",
"version": "14.25.1",
"description": "A powerful library for interacting with the Discord API",
"scripts": {
"test": "pnpm run docs:test && pnpm run test:typescript",

View File

@@ -11,15 +11,19 @@ const Messages = require('./Messages');
* @ignore
*/
function makeDiscordjsError(Base) {
return class DiscordjsError extends Base {
return class extends Base {
static {
Object.defineProperty(this, 'name', { value: `Discordjs${Base.name}` });
}
constructor(code, ...args) {
super(message(code, args));
this.code = code;
Error.captureStackTrace?.(this, DiscordjsError);
Error.captureStackTrace(this, this.constructor);
}
get name() {
return `${super.name} [${this.code}]`;
return `${this.constructor.name} [${this.code}]`;
}
};
}

View File

@@ -115,7 +115,8 @@ const Messages = {
[DjsErrorCodes.EmojiType]: 'Emoji must be a string or GuildEmoji/ReactionEmoji',
[DjsErrorCodes.EmojiManaged]: 'Emoji is managed and has no Author.',
[DjsErrorCodes.MissingManageGuildExpressionsPermission]: guild =>
`Client must have Manage Guild Expressions permission in guild ${guild} to see emoji authors.`,
// eslint-disable-next-line max-len
`Client must have Create Guild Expressions or Manage Guild Expressions permission in guild ${guild} to see emoji authors.`,
[DjsErrorCodes.MissingManageEmojisAndStickersPermission]: guild =>
`Client must have Manage Emojis and Stickers permission in guild ${guild} to see emoji authors.`,

View File

@@ -161,7 +161,7 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
const { me } = this.guild.members;
if (!me) throw new DiscordjsError(ErrorCodes.GuildUncachedMe);
if (!me.permissions.has(PermissionFlagsBits.ManageGuildExpressions)) {
if (!me.permissions.any(PermissionFlagsBits.CreateGuildExpressions | PermissionFlagsBits.ManageGuildExpressions)) {
throw new DiscordjsError(ErrorCodes.MissingManageGuildExpressionsPermission, this.guild);
}