Compare commits

...

8 Commits

Author SHA1 Message Date
Vlad Frangu
2550c7931d chore(discord.js): release discord.js@14.14.1 (#9957)
* chore(discord.js): release discord.js@14.14.1

* chore: actual changelog
2023-11-12 22:06:14 +00:00
Almeida
40726db722 refactor: use formatters (#9956)
* refactor: use formatters

* fix: imports

* fix: imports pt.2

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-11-12 21:56:10 +00:00
Aura
1e4ef35436 docs: use preferred nullable syntax (?T over T | null) (#9946)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-11-12 21:45:02 +00:00
Aura
4bc1dae36f types: use wrapper utilities (#9945)
* types: use `Awaitable<T>` instead of `Promise<T> | T`

* types: use `JSONEncodable<T>` over raw definition

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-11-12 21:40:59 +00:00
Almeida
cc07a28f12 fix(Emoji): id set as undefined edge case (#9953) 2023-11-12 21:34:24 +00:00
Jiralite
f93abf7e35 fix(BaseClient): Default in objects properly (#9952)
fix(BaseClient): default in objects properly
2023-11-12 21:14:09 +00:00
Jiralite
f0ec70dfda feat: bump package versions (#9951)
* feat: bump package versions

* chore(create-discord-bot): release create-discord-bot@0.2.3

---------

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
2023-11-12 20:22:55 +00:00
Jaw0r3k
8a6045f600 fix: import picocolors as default (#9949) 2023-11-12 19:39:08 +00:00
34 changed files with 110 additions and 66 deletions

View File

@@ -2,6 +2,16 @@
All notable changes to this project will be documented in this file.
# [create-discord-bot@0.2.3](https://github.com/discordjs/discord.js/compare/create-discord-bot/0.2.2...create-discord-bot/0.2.3) - (2023-11-12)
## Bug Fixes
- Import picocolors as default (#9949) ([8a6045f](https://github.com/discordjs/discord.js/commit/8a6045f6003971dbf64c8576f08631751b982ae4))
## Features
- Bump package versions ([e8bd354](https://github.com/discordjs/discord.js/commit/e8bd35405239616b12cb5f09eb983f5251298aca))
# [create-discord-bot@0.2.2](https://github.com/discordjs/discord.js/compare/create-discord-bot@0.2.1...create-discord-bot@0.2.2) - (2023-11-12)
## Bug Fixes

View File

@@ -3,7 +3,7 @@
// eslint-disable-next-line n/shebang
import process from 'node:process';
import { Option, program } from 'commander';
import { red, yellow, green } from 'picocolors';
import picocolors from 'picocolors';
import prompts from 'prompts';
import validateProjectName from 'validate-npm-package-name';
import packageJSON from '../package.json' assert { type: 'json' };
@@ -34,7 +34,7 @@ program
.version(packageJSON.version)
.description('Create a basic discord.js bot.')
.argument('[directory]', 'What is the name of the directory you want to create this project in?')
.usage(`${green('<directory>')}`)
.usage(`${picocolors.green('<directory>')}`)
.action((directory) => {
projectDirectory = directory;
})
@@ -68,13 +68,13 @@ if (!projectDirectory) {
const errors = [];
for (const error of [...(validationResult.errors ?? []), ...(validationResult.warnings ?? [])]) {
errors.push(red(`- ${error}`));
errors.push(picocolors.red(`- ${error}`));
}
return red(
`Cannot create a project named ${yellow(
return picocolors.red(
`Cannot create a project named ${picocolors.yellow(
`"${directory}"`,
)} due to npm naming restrictions.\n\nErrors:\n${errors.join('\n')}\n\n${red(
)} due to npm naming restrictions.\n\nErrors:\n${errors.join('\n')}\n\n${picocolors.red(
'\nSee https://docs.npmjs.com/cli/configuring-npm/package-json for more details.',
)}}`,
);

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "create-discord-bot",
"version": "0.2.2",
"version": "0.2.3",
"description": "A simple way to create a startup Discord bot.",
"scripts": {
"build": "tsc --noEmit && tsup",

View File

@@ -11,8 +11,8 @@
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
},
"dependencies": {
"@discordjs/core": "^1.0.1",
"discord.js": "^14.13.0"
"@discordjs/core": "^1.1.0",
"discord.js": "^14.14.0"
},
"devDependencies": {
"@sapphire/ts-config": "^4.0.1",

View File

@@ -11,8 +11,8 @@
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
},
"dependencies": {
"@discordjs/core": "^1.0.1",
"discord.js": "^14.13.0"
"@discordjs/core": "^1.1.0",
"discord.js": "^14.14.0"
},
"devDependencies": {
"@sapphire/ts-config": "^5.0.0",

View File

@@ -1,4 +1,4 @@
import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'npm:discord.js@^14.13.0';
import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'npm:discord.js@^14.14.0';
import type { StructurePredicate } from '../util/loaders.ts';
/**

View File

@@ -1,4 +1,4 @@
import type { ClientEvents } from 'npm:discord.js@^14.13.0';
import type { ClientEvents } from 'npm:discord.js@^14.14.0';
import type { StructurePredicate } from '../util/loaders.ts';
/**

View File

@@ -1,4 +1,4 @@
import { Events } from 'npm:discord.js@^14.13.0';
import { Events } from 'npm:discord.js@^14.14.0';
import type { Event } from './index.ts';
export default {

View File

@@ -1,6 +1,6 @@
import 'https://deno.land/std@0.199.0/dotenv/load.ts';
import { URL } from 'node:url';
import { Client, GatewayIntentBits } from 'npm:discord.js@^14.13.0';
import { Client, GatewayIntentBits } from 'npm:discord.js@^14.14.0';
import { loadCommands, loadEvents } from './util/loaders.ts';
import { registerEvents } from './util/registerEvents.ts';

View File

@@ -1,7 +1,7 @@
import 'https://deno.land/std@0.199.0/dotenv/load.ts';
import { URL } from 'node:url';
import { API } from 'npm:@discordjs/core@^1.0.1/http-only';
import { REST } from 'npm:discord.js@^14.13.0';
import { API } from 'npm:@discordjs/core@^1.1.0/http-only';
import { REST } from 'npm:discord.js@^14.14.0';
import { loadCommands } from './loaders.ts';
const commands = await loadCommands(new URL('../commands/', import.meta.url));

View File

@@ -1,4 +1,4 @@
import { Events, type Client } from 'npm:discord.js@^14.13.0';
import { Events, type Client } from 'npm:discord.js@^14.14.0';
import type { Command } from '../commands/index.ts';
import type { Event } from '../events/index.ts';

View File

@@ -11,8 +11,8 @@
"deploy": "node --require dotenv/config src/util/deploy.js"
},
"dependencies": {
"@discordjs/core": "^1.0.1",
"discord.js": "^14.13.0",
"@discordjs/core": "^1.1.0",
"discord.js": "^14.14.0",
"dotenv": "^16.3.1"
},
"devDependencies": {

View File

@@ -12,8 +12,8 @@
"start": "node --require dotenv/config dist/index.js"
},
"dependencies": {
"@discordjs/core": "^1.0.1",
"discord.js": "^14.13.0",
"@discordjs/core": "^1.1.0",
"discord.js": "^14.14.0",
"dotenv": "^16.3.1"
},
"devDependencies": {

View File

@@ -2,6 +2,25 @@
All notable changes to this project will be documented in this file.
# [14.14.1](https://github.com/discordjs/discord.js/compare/14.14.0...14.14.1) - (2023-11-12)
## Bug Fixes
- **Emoji:** `id` set as `undefined` edge case (#9953) ([cc07a28](https://github.com/discordjs/discord.js/commit/cc07a28f125be63a7f1132a5a07d317c160f9a89))
- **BaseClient:** Default in objects properly (#9952) ([f93abf7](https://github.com/discordjs/discord.js/commit/f93abf7e35ab6793aa530ceadc279d8c80b7aebf))
## Documentation
- Use preferred nullable syntax (`?T` over `T | null`) (#9946) ([1e4ef35](https://github.com/discordjs/discord.js/commit/1e4ef35436cd134db70c1c3152e33342baf9d6b6))
## Refactor
- Use formatters (#9956) ([40726db](https://github.com/discordjs/discord.js/commit/40726db722c7851f4096cda29667ea4ee89da98b))
## Typings
- Use wrapper utilities (#9945) ([4bc1dae](https://github.com/discordjs/discord.js/commit/4bc1dae36f01649127774c40b14e778d65cf25c5))
# [14.14.0](https://github.com/discordjs/discord.js/compare/14.13.0...14.14.0) - (2023-11-12)
## Bug Fixes

View File

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

View File

@@ -27,11 +27,20 @@ class BaseClient extends EventEmitter {
this.options = {
...defaultOptions,
...options,
presence: {
...defaultOptions.presence,
...options.presence,
},
sweepers: {
...defaultOptions.sweepers,
...options.sweepers,
},
ws: {
...defaultOptions.ws,
...options.ws,
},
rest: {
...defaultOptions.rest,
...options.rest,
userAgentAppendix: options.rest?.userAgentAppendix
? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`

View File

@@ -93,7 +93,7 @@ class GuildMemberManager extends CachedManager {
* <info>This method requires the {@link PermissionFlagsBits.CreateInstantInvite} permission.
* @param {UserResolvable} user The user to add to the guild
* @param {AddGuildMemberOptions} options Options for adding the user to the guild
* @returns {Promise<GuildMember|null>}
* @returns {Promise<?GuildMember>}
*/
async add(user, options) {
const userId = this.client.users.resolveId(user);
@@ -326,9 +326,9 @@ class GuildMemberManager extends CachedManager {
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles or role ids to apply
* @property {boolean} [mute] Whether or not the member should be muted
* @property {boolean} [deaf] Whether or not the member should be deafened
* @property {GuildVoiceChannelResolvable|null} [channel] Channel to move the member to
* @property {?GuildVoiceChannelResolvable} [channel] Channel to move the member to
* (if they are connected to voice), or `null` if you want to disconnect them from voice
* @property {DateResolvable|null} [communicationDisabledUntil] The date or timestamp
* @property {?DateResolvable} [communicationDisabledUntil] The date or timestamp
* for the member's communication to be disabled until. Provide `null` to enable communication again.
* @property {GuildMemberFlagsResolvable} [flags] The flags to set for the member
* @property {string} [reason] Reason for editing this user
@@ -400,7 +400,7 @@ class GuildMemberManager extends CachedManager {
/**
* Prunes members from the guild based on how long they have been inactive.
* @param {GuildPruneMembersOptions} [options] Options for pruning
* @returns {Promise<number|null>} The number of members that were/will be kicked
* @returns {Promise<?number>} The number of members that were/will be kicked
* @example
* // See how many members will be pruned
* guild.members.prune({ dry: true })

View File

@@ -144,7 +144,7 @@ class ApplicationCommand extends Base {
/**
* Whether the command can be used in DMs
* <info>This property is always `null` on guild commands</info>
* @type {boolean|null}
* @type {?boolean}
*/
this.dmPermission = data.dm_permission;
} else {

View File

@@ -1,6 +1,6 @@
'use strict';
const { channelLink } = require('@discordjs/builders');
const { channelLink, channelMention } = require('@discordjs/formatters');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { ChannelType, Routes } = require('discord-api-types/v10');
const Base = require('./Base');
@@ -89,7 +89,7 @@ class BaseChannel extends Base {
* console.log(`Hello from ${channel}!`);
*/
toString() {
return `<#${this.id}>`;
return channelMention(this.id);
}
/**

View File

@@ -1,6 +1,6 @@
'use strict';
const { userMention } = require('@discordjs/builders');
const { userMention } = require('@discordjs/formatters');
const { ChannelType } = require('discord-api-types/v10');
const { BaseChannel } = require('./BaseChannel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');

View File

@@ -1,6 +1,7 @@
'use strict';
const process = require('node:process');
const { formatEmoji } = require('@discordjs/formatters');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const Base = require('./Base');
@@ -29,7 +30,7 @@ class Emoji extends Base {
* The emoji's id
* @type {?Snowflake}
*/
this.id = emoji.id;
this.id = emoji.id ?? null;
}
/**
@@ -97,7 +98,7 @@ class Emoji extends Base {
* reaction.message.channel.send(`The emoji used was: ${reaction.emoji}`);
*/
toString() {
return this.id ? `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>` : this.name;
return this.id ? formatEmoji(this.id, this.animated) : this.name;
}
toJSON() {

View File

@@ -404,7 +404,7 @@ class GuildMember extends Base {
/**
* Times this guild member out.
* @param {DateResolvable|null} communicationDisabledUntil The date or timestamp
* @param {?DateResolvable} communicationDisabledUntil The date or timestamp
* for the member's communication to be disabled until. Provide `null` to remove the timeout.
* @param {string} [reason] The reason for this timeout.
* @returns {Promise<GuildMember>}
@@ -425,7 +425,7 @@ class GuildMember extends Base {
/**
* Times this guild member out.
* @param {number|null} timeout The duration in milliseconds
* @param {?number} timeout The duration in milliseconds
* for the member's communication to be disabled. Provide `null` to remove the timeout.
* @param {string} [reason] The reason for this timeout.
* @returns {Promise<GuildMember>}

View File

@@ -1,7 +1,7 @@
'use strict';
const { messageLink } = require('@discordjs/builders');
const { Collection } = require('@discordjs/collection');
const { messageLink } = require('@discordjs/formatters');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const {
InteractionType,

View File

@@ -1,5 +1,6 @@
'use strict';
const { roleMention } = require('@discordjs/formatters');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { PermissionFlagsBits } = require('discord-api-types/v10');
const Base = require('./Base');
@@ -452,7 +453,7 @@ class Role extends Base {
*/
toString() {
if (this.id === this.guild.id) return '@everyone';
return `<@&${this.id}>`;
return roleMention(this.id);
}
toJSON() {

View File

@@ -310,7 +310,7 @@ class ThreadChannel extends BaseChannel {
* or when the original message in the parent channel is deleted.
* If you just need the id of that message, use {@link ThreadChannel#id} instead.</info>
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<Message<true>|null>}
* @returns {Promise<?Message<true>>}
*/
// eslint-disable-next-line require-await
async fetchStarterMessage(options) {

View File

@@ -1,6 +1,6 @@
'use strict';
const { userMention } = require('@discordjs/builders');
const { userMention } = require('@discordjs/formatters');
const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const Base = require('./Base');

View File

@@ -197,7 +197,7 @@ class VoiceState extends Base {
/**
* Moves the member to a different channel, or disconnects them from the one they're in.
* @param {GuildVoiceChannelResolvable|null} channel Channel to move the member to, or `null` if you want to
* @param {?GuildVoiceChannelResolvable} channel Channel to move the member to, or `null` if you want to
* disconnect them from voice.
* @param {string} [reason] Reason for moving member to another channel or disconnecting
* @returns {Promise<GuildMember>}

View File

@@ -81,7 +81,7 @@ class Collector extends EventEmitter {
/**
* The reason the collector ended
* @type {string|null}
* @type {?string}
* @private
*/
this._endReason = null;

View File

@@ -55,7 +55,7 @@ class TextBasedChannel {
/**
* The base message options for messages.
* @typedef {Object} BaseMessageOptions
* @property {string|null} [content=''] The content for the message. This can only be `null` when editing a message.
* @property {?string} [content=''] The content for the message. This can only be `null` when editing a message.
* @property {Array<(EmbedBuilder|Embed|APIEmbed)>} [embeds] The embeds for the message
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
* (see [here](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for more details)

View File

@@ -19,7 +19,7 @@ const {
TimestampStyles,
underscore,
userMention,
} = require('@discordjs/builders');
} = require('@discordjs/formatters');
/**
* Formats an application command name and id into an application command mention.

View File

@@ -7,7 +7,7 @@ const { DiscordjsTypeError, ErrorCodes } = require('../errors');
/**
* @typedef {Function} GlobalSweepFilter
* @returns {Function|null} Return `null` to skip sweeping, otherwise a function passed to `sweep()`,
* @returns {?Function} Return `null` to skip sweeping, otherwise a function passed to `sweep()`,
* See {@link [Collection#sweep](https://discord.js.org/docs/packages/collection/stable/Collection:Class#sweep)}
* for the definition of this function.
*/

View File

@@ -1,19 +1,8 @@
import {
ActionRowBuilder as BuilderActionRow,
MessageActionRowComponentBuilder,
blockQuote,
bold,
ButtonBuilder as BuilderButtonComponent,
channelMention,
codeBlock,
EmbedBuilder as BuildersEmbed,
formatEmoji,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
quote,
roleMention,
ChannelSelectMenuBuilder as BuilderChannelSelectMenuComponent,
MentionableSelectMenuBuilder as BuilderMentionableSelectMenuComponent,
RoleSelectMenuBuilder as BuilderRoleSelectMenuComponent,
@@ -21,12 +10,6 @@ import {
UserSelectMenuBuilder as BuilderUserSelectMenuComponent,
TextInputBuilder as BuilderTextInputComponent,
SelectMenuOptionBuilder as BuildersSelectMenuOption,
spoiler,
strikethrough,
time,
TimestampStyles,
underscore,
userMention,
ModalActionRowComponentBuilder,
ModalBuilder as BuildersModal,
AnyComponentBuilder,
@@ -34,6 +17,25 @@ import {
type RestOrArray,
ApplicationCommandOptionAllowedChannelTypes,
} from '@discordjs/builders';
import {
blockQuote,
bold,
channelMention,
codeBlock,
formatEmoji,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
quote,
roleMention,
spoiler,
strikethrough,
time,
TimestampStyles,
underscore,
userMention,
} from '@discordjs/formatters';
import { Awaitable, JSONEncodable } from '@discordjs/util';
import { Collection, ReadonlyCollection } from '@discordjs/collection';
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
@@ -1129,7 +1131,7 @@ export abstract class Collector<Key, Value, Extras extends unknown[] = []> exten
public toJSON(): unknown;
protected listener: (...args: any[]) => void;
public abstract collect(...args: unknown[]): Key | null | Promise<Key | null>;
public abstract collect(...args: unknown[]): Awaitable<Key | null>;
public abstract dispose(...args: unknown[]): Key | null;
public on<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
@@ -5066,7 +5068,7 @@ export interface CloseEvent {
reason: string;
}
export type CollectorFilter<Arguments extends unknown[]> = (...args: Arguments) => boolean | Promise<boolean>;
export type CollectorFilter<Arguments extends unknown[]> = (...args: Arguments) => Awaitable<boolean>;
export interface CollectorOptions<FilterArguments extends unknown[]> {
filter?: CollectorFilter<FilterArguments>;
@@ -6647,7 +6649,7 @@ export type Serialized<Value> = Value extends symbol | bigint | (() => any)
? never
: Value extends number | string | boolean | undefined
? Value
: Value extends { toJSON(): infer JSONResult }
: Value extends JSONEncodable<infer JSONResult>
? JSONResult
: Value extends ReadonlyArray<infer ItemType>
? Serialized<ItemType>[]

View File

@@ -185,6 +185,7 @@ import {
PartialEmojiOnlyId,
Emoji,
PartialEmoji,
Awaitable,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -412,7 +413,7 @@ client.on('messageCreate', async message => {
(
test: ButtonInteraction<'cached'>,
items: Collection<Snowflake, ButtonInteraction<'cached'>>,
) => boolean | Promise<boolean>
) => Awaitable<boolean>
>(buttonCollector.filter);
expectType<GuildTextBasedChannel>(message.channel);
expectType<Guild>(message.guild);

View File

@@ -1,6 +1,7 @@
import type { Readable } from 'node:stream';
import type { ReadableStream } from 'node:stream/web';
import type { Collection } from '@discordjs/collection';
import type { Awaitable } from '@discordjs/util';
import type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';
import type { IHandler } from '../interfaces/Handler.js';
@@ -183,7 +184,7 @@ export interface RateLimitData {
/**
* A function that determines whether the rate limit hit should throw an Error
*/
export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean;
export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
export interface APIRequest {
/**