Compare commits

..

8 Commits

Author SHA1 Message Date
Vlad Frangu
776880d06b chore: fix changelogs 2024-05-05 21:00:59 +03:00
Vlad Frangu
c05244af61 chore(discord.js): release discord.js@14.15.2 2024-05-05 21:00:59 +03:00
Vlad Frangu
12deea85e5 chore(builders): release @discordjs/builders@1.8.1 2024-05-05 21:00:59 +03:00
Qjuh
07c12101e5 fix: slashcommand builder type split (#10253) 2024-05-05 10:03:14 +00:00
XCraftTM
30d79e85fb fix(PollAnswer): fetchVoters route changed to MessageManager (#10251)
Update PollAnswer.js
2024-05-04 21:18:04 +00:00
Vlad Frangu
f2794e1221 chore(discord.js): release discord.js@14.15.1 (#10250)
* chore(discord.js): release discord.js@14.15.1

* chore: fix changelog

* chore: update link
2024-05-04 19:18:07 +00:00
DD
0474a43751 fix(MessageManager): poll methods don't need a channel id (#10249)
* fix(MessageManager): end poll does not need channel id

* chore: rest of the work
2024-05-04 19:06:03 +00:00
Almeida
c91d03c535 ci: fix documentation workflow (#10248) 2024-05-04 18:18:45 +00:00
16 changed files with 164 additions and 128 deletions

View File

@@ -75,7 +75,7 @@ jobs:
- name: Apply tag to api-extractor config
if: ${{ env.REF_TYPE == 'tag' && !inputs.ref }}
run: sed -i 's!https://github.com/discordjs/discord.js/tree/main!https://github.com/discordjs/discord.js/tree/${{ steps.extract-tag.outputs.semver }}!' "packages/${{ steps.extract-tag.outputs.package}}/"
run: sed -i 's!https://github.com/discordjs/discord.js/tree/main!https://github.com/discordjs/discord.js/tree/${{ steps.extract-tag.outputs.semver }}!' "packages/${{ steps.extract-tag.outputs.package}}/api-extractor.json"
- name: Build docs
run: pnpm run docs

View File

@@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
# [@discordjs/builders@1.8.1](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.8.0...@discordjs/builders@1.8.1) - (2024-05-05)
## Bug Fixes
- Slashcommand builder type split (#10253) ([07c1210](https://github.com/discordjs/discord.js/commit/07c12101e534fdce836a94bc571b53f75979ea86))
# [@discordjs/builders@1.8.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.7.0...@discordjs/builders@1.8.0) - (2024-05-04)
## Bug Fixes

View File

@@ -357,6 +357,10 @@ describe('Slash Commands', () => {
getBuilder().addStringOption(getStringOption().setChoices({ name: 'owo', value: 'uwu' })),
).not.toThrowError();
});
test('GIVEN valid builder with NSFW, THEN does not throw error', () => {
expect(() => getBuilder().setName('foo').setDescription('foo').setNSFW(true)).not.toThrowError();
});
});
describe('Builder with subcommand (group) options', () => {
@@ -519,6 +523,14 @@ describe('Slash Commands', () => {
expect(() => getBuilder().setDefaultMemberPermissions(1.1)).toThrowError();
});
test('GIVEN valid permission with options THEN does not throw error', () => {
expect(() =>
getBuilder().addBooleanOption(getBooleanOption()).setDefaultMemberPermissions('1'),
).not.toThrowError();
expect(() => getBuilder().addChannelOption(getChannelOption()).setDMPermission(false)).not.toThrowError();
});
});
});
});

View File

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

View File

@@ -140,7 +140,7 @@ export class TextInputBuilder
}
/**
* {@inheritDoc Equatable.equals}
* Whether this is equal to another structure.
*/
public equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean {
if (isJSONEncodable(other)) {

View File

@@ -54,6 +54,7 @@ export * from './interactions/slashCommands/mixins/ApplicationCommandOptionWithC
export * from './interactions/slashCommands/mixins/NameAndDescription.js';
export * from './interactions/slashCommands/mixins/SharedSlashCommandOptions.js';
export * from './interactions/slashCommands/mixins/SharedSubcommands.js';
export * from './interactions/slashCommands/mixins/SharedSlashCommand.js';
export * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions.js';
export * from './interactions/contextMenuCommands/ContextMenuCommandBuilder.js';

View File

@@ -1,13 +1,14 @@
import type { APIApplicationCommandOption, LocalizationMap, Permissions } from 'discord-api-types/v10';
import { mix } from 'ts-mixer';
import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
import { SharedSlashCommand } from './mixins/SharedSlashCommand.js';
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';
import { SharedSlashCommandSubcommands } from './mixins/SharedSubcommands.js';
/**
* A builder that creates API-compatible JSON data for slash commands.
*/
@mix(SharedSlashCommandOptions, SharedNameAndDescription, SharedSlashCommandSubcommands)
@mix(SharedSlashCommandOptions, SharedNameAndDescription, SharedSlashCommandSubcommands, SharedSlashCommand)
export class SlashCommandBuilder {
/**
* The name of this command.
@@ -37,7 +38,7 @@ export class SlashCommandBuilder {
/**
* Whether this command is enabled by default when the application is added to a guild.
*
* @deprecated Use {@link SharedSlashCommandSubcommands.setDefaultMemberPermissions} or {@link SharedSlashCommandSubcommands.setDMPermission} instead.
* @deprecated Use {@link SharedSlashCommand.setDefaultMemberPermissions} or {@link SharedSlashCommand.setDMPermission} instead.
*/
public readonly default_permission: boolean | undefined = undefined;
@@ -63,14 +64,16 @@ export class SlashCommandBuilder {
export interface SlashCommandBuilder
extends SharedNameAndDescription,
SharedSlashCommandOptions<SlashCommandOptionsOnlyBuilder>,
SharedSlashCommandSubcommands<SlashCommandSubcommandsOnlyBuilder> {}
SharedSlashCommandSubcommands<SlashCommandSubcommandsOnlyBuilder>,
SharedSlashCommand {}
/**
* An interface specifically for slash command subcommands.
*/
export interface SlashCommandSubcommandsOnlyBuilder
extends SharedNameAndDescription,
SharedSlashCommandSubcommands<SlashCommandSubcommandsOnlyBuilder> {}
SharedSlashCommandSubcommands<SlashCommandSubcommandsOnlyBuilder>,
SharedSlashCommand {}
/**
* An interface specifically for slash command options.
@@ -78,7 +81,7 @@ export interface SlashCommandSubcommandsOnlyBuilder
export interface SlashCommandOptionsOnlyBuilder
extends SharedNameAndDescription,
SharedSlashCommandOptions<SlashCommandOptionsOnlyBuilder>,
ToAPIApplicationCommandOptions {}
SharedSlashCommand {}
/**
* An interface that ensures the `toJSON()` call will return something

View File

@@ -0,0 +1,112 @@
import type {
LocalizationMap,
Permissions,
RESTPostAPIChatInputApplicationCommandsJSONBody,
} from 'discord-api-types/v10';
import {
validateDMPermission,
validateDefaultMemberPermissions,
validateDefaultPermission,
validateLocalizationMap,
validateNSFW,
validateRequiredParameters,
} from '../Assertions.js';
import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder.js';
/**
* This mixin holds symbols that can be shared in slashcommands independent of options or subcommands.
*/
export class SharedSlashCommand {
public readonly name: string = undefined!;
public readonly name_localizations?: LocalizationMap;
public readonly description: string = undefined!;
public readonly description_localizations?: LocalizationMap;
public readonly options: ToAPIApplicationCommandOptions[] = [];
/**
* Sets whether the command is enabled by default when the application is added to a guild.
*
* @remarks
* If set to `false`, you will have to later `PUT` the permissions for this command.
* @param value - Whether or not to enable this command by default
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
* @deprecated Use {@link SharedSlashCommand.setDefaultMemberPermissions} or {@link SharedSlashCommand.setDMPermission} instead.
*/
public setDefaultPermission(value: boolean) {
// Assert the value matches the conditions
validateDefaultPermission(value);
Reflect.set(this, 'default_permission', value);
return this;
}
/**
* Sets the default permissions a member should have in order to run the command.
*
* @remarks
* You can set this to `'0'` to disable the command by default.
* @param permissions - The permissions bit field to set
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
public setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {
// Assert the value and parse it
const permissionValue = validateDefaultMemberPermissions(permissions);
Reflect.set(this, 'default_member_permissions', permissionValue);
return this;
}
/**
* Sets if the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This method is only for global commands.
* @param enabled - Whether the command should be enabled in direct messages
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
public setDMPermission(enabled: boolean | null | undefined) {
// Assert the value matches the conditions
validateDMPermission(enabled);
Reflect.set(this, 'dm_permission', enabled);
return this;
}
/**
* Sets whether this command is NSFW.
*
* @param nsfw - Whether this command is NSFW
*/
public setNSFW(nsfw = true) {
// Assert the value matches the conditions
validateNSFW(nsfw);
Reflect.set(this, 'nsfw', nsfw);
return this;
}
/**
* Serializes this builder to API-compatible JSON data.
*
* @remarks
* This method runs validations on the data before serializing it.
* As such, it may throw an error if the data is invalid.
*/
public toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
validateRequiredParameters(this.name, this.description, this.options);
validateLocalizationMap(this.name_localizations);
validateLocalizationMap(this.description_localizations);
return {
...this,
options: this.options.map((option) => option.toJSON()),
};
}
}

View File

@@ -1,18 +1,4 @@
import type {
LocalizationMap,
Permissions,
RESTPostAPIChatInputApplicationCommandsJSONBody,
} from 'discord-api-types/v10';
import {
assertReturnOfBuilder,
validateDMPermission,
validateDefaultMemberPermissions,
validateDefaultPermission,
validateLocalizationMap,
validateMaxOptionsLength,
validateNSFW,
validateRequiredParameters,
} from '../Assertions.js';
import { assertReturnOfBuilder, validateMaxOptionsLength } from '../Assertions.js';
import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder.js';
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from '../SlashCommandSubcommands.js';
@@ -24,80 +10,8 @@ import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } fro
export class SharedSlashCommandSubcommands<
TypeAfterAddingSubcommands extends SharedSlashCommandSubcommands<TypeAfterAddingSubcommands>,
> {
public readonly name: string = undefined!;
public readonly name_localizations?: LocalizationMap;
public readonly description: string = undefined!;
public readonly description_localizations?: LocalizationMap;
public readonly options: ToAPIApplicationCommandOptions[] = [];
/**
* Sets whether the command is enabled by default when the application is added to a guild.
*
* @remarks
* If set to `false`, you will have to later `PUT` the permissions for this command.
* @param value - Whether or not to enable this command by default
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
* @deprecated Use {@link SharedSlashCommandSubcommands.setDefaultMemberPermissions} or {@link SharedSlashCommandSubcommands.setDMPermission} instead.
*/
public setDefaultPermission(value: boolean) {
// Assert the value matches the conditions
validateDefaultPermission(value);
Reflect.set(this, 'default_permission', value);
return this;
}
/**
* Sets the default permissions a member should have in order to run the command.
*
* @remarks
* You can set this to `'0'` to disable the command by default.
* @param permissions - The permissions bit field to set
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
public setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {
// Assert the value and parse it
const permissionValue = validateDefaultMemberPermissions(permissions);
Reflect.set(this, 'default_member_permissions', permissionValue);
return this;
}
/**
* Sets if the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This method is only for global commands.
* @param enabled - Whether the command should be enabled in direct messages
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
public setDMPermission(enabled: boolean | null | undefined) {
// Assert the value matches the conditions
validateDMPermission(enabled);
Reflect.set(this, 'dm_permission', enabled);
return this;
}
/**
* Sets whether this command is NSFW.
*
* @param nsfw - Whether this command is NSFW
*/
public setNSFW(nsfw = true) {
// Assert the value matches the conditions
validateNSFW(nsfw);
Reflect.set(this, 'nsfw', nsfw);
return this;
}
/**
* Adds a new subcommand group to this command.
*
@@ -149,23 +63,4 @@ export class SharedSlashCommandSubcommands<
return this as unknown as TypeAfterAddingSubcommands;
}
/**
* Serializes this builder to API-compatible JSON data.
*
* @remarks
* This method runs validations on the data before serializing it.
* As such, it may throw an error if the data is invalid.
*/
public toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
validateRequiredParameters(this.name, this.description, this.options);
validateLocalizationMap(this.name_localizations);
validateLocalizationMap(this.description_localizations);
return {
...this,
options: this.options.map((option) => option.toJSON()),
};
}
}

View File

@@ -2,6 +2,18 @@
All notable changes to this project will be documented in this file.
# [14.15.2](https://github.com/discordjs/discord.js/compare/14.15.1...14.15.2) - (2024-05-05)
## Bug Fixes
- **PollAnswer:** FetchVoters route changed to MessageManager (#10251) ([30d79e8](https://github.com/discordjs/discord.js/commit/30d79e85fb8502aee5c63fe7effd9029e347d266))
# [14.15.1](https://github.com/discordjs/discord.js/compare/14.15.0...14.15.1) - (2024-05-04)
## Bug Fixes
- **MessageManager:** Poll methods don't need a channel id (#10249) ([0474a43](https://github.com/discordjs/discord.js/commit/0474a4375146b57b35074dadbaa83274416f899e))
# [14.15.0](https://github.com/discordjs/discord.js/compare/14.14.1...14.15.0) - (2024-05-04)
## Bug Fixes

View File

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

View File

@@ -269,19 +269,17 @@ class MessageManager extends CachedManager {
/**
* Ends a poll.
* @param {Snowflake} channelId The id of the channel
* @param {Snowflake} messageId The id of the message
* @returns {Promise<Message>}
*/
async endPoll(channelId, messageId) {
const message = await this.client.rest.post(Routes.expirePoll(channelId, messageId));
async endPoll(messageId) {
const message = await this.client.rest.post(Routes.expirePoll(this.channel.id, messageId));
return this._add(message, false);
}
/**
* Options used for fetching voters of an answer in a poll.
* @typedef {BaseFetchPollAnswerVotersOptions} FetchPollAnswerVotersOptions
* @param {Snowflake} channelId The id of the channel
* @param {Snowflake} messageId The id of the message
* @param {number} answerId The id of the answer
*/
@@ -291,8 +289,8 @@ class MessageManager extends CachedManager {
* @param {FetchPollAnswerVotersOptions} options The options for fetching the poll answer voters
* @returns {Promise<Collection<Snowflake, User>>}
*/
async fetchPollAnswerVoters({ channelId, messageId, answerId, after, limit }) {
const voters = await this.client.rest.get(Routes.pollAnswerVoters(channelId, messageId, answerId), {
async fetchPollAnswerVoters({ messageId, answerId, after, limit }) {
const voters = await this.client.rest.get(Routes.pollAnswerVoters(this.channel.id, messageId, answerId), {
query: makeURLSearchParams({ limit, after }),
});

View File

@@ -102,7 +102,7 @@ class Poll extends Base {
return Promise.reject(new DiscordjsError(ErrorCodes.PollAlreadyExpired));
}
return this.message.channel.messages.endPoll(this.message.channel.id, this.message.id);
return this.message.channel.messages.endPoll(this.message.id);
}
}

View File

@@ -77,8 +77,7 @@ class PollAnswer extends Base {
* @returns {Promise<Collection<Snowflake, User>>}
*/
fetchVoters({ after, limit } = {}) {
return this.poll.message.channel.fetchPollAnswerVoters({
channelId: this.poll.message.channel.id,
return this.poll.message.channel.messages.fetchPollAnswerVoters({
messageId: this.poll.message.id,
answerId: this.id,
after,

View File

@@ -4399,7 +4399,6 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
}
export interface FetchPollAnswerVotersOptions extends BaseFetchPollAnswerVotersOptions {
channelId: Snowflake;
messageId: Snowflake;
answerId: number;
}
@@ -4422,7 +4421,7 @@ export abstract class MessageManager<InGuild extends boolean = boolean> extends
public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;
public pin(message: MessageResolvable, reason?: string): Promise<void>;
public unpin(message: MessageResolvable, reason?: string): Promise<void>;
public endPoll(channelId: Snowflake, messageId: Snowflake): Promise<Message>;
public endPoll(messageId: Snowflake): Promise<Message>;
public fetchPollAnswerVoters(options: FetchPollAnswerVotersOptions): Promise<Collection<Snowflake, User>>;
}

View File

@@ -2549,9 +2549,8 @@ declare const poll: Poll;
expectType<Collection<Snowflake, User>>(await answer.fetchVoters({ after: snowflake, limit: 10 }));
await messageManager.endPoll(snowflake, snowflake);
await messageManager.endPoll(snowflake);
await messageManager.fetchPollAnswerVoters({
channelId: snowflake,
messageId: snowflake,
answerId: 1,
});