Merge remote-tracking branch 'upstream/master' into inline-replies

This commit is contained in:
monbrey 2020-11-17 10:40:31 +11:00
commit 1028183c23
39 changed files with 914 additions and 748 deletions

View file

@ -11,7 +11,7 @@ is a great boon to your development process.
To get ready to work on the codebase, please do the following: To get ready to work on the codebase, please do the following:
1. Fork & clone the repository, and make sure you're on the **master** branch 1. Fork & clone the repository, and make sure you're on the **master** branch
2. Run `npm install` 2. Run `npm ci`
3. If you're working on voice, also run `npm install @discordjs/opus` or `npm install opusscript` 3. If you're working on voice, also run `npm install @discordjs/opus` or `npm install opusscript`
4. Code your heart out! 4. Code your heart out!
5. Run `npm test` to run ESLint and ensure any JSDoc changes are valid 5. Run `npm test` to run ESLint and ensure any JSDoc changes are valid

View file

@ -21,7 +21,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Build and deploy documentation - name: Build and deploy documentation
uses: discordjs/action-docs@v1 uses: discordjs/action-docs@v1
@ -41,7 +41,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Build and deploy webpack - name: Build and deploy webpack
uses: discordjs/action-webpack@v1 uses: discordjs/action-webpack@v1

View file

@ -16,7 +16,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run ESLint - name: Run ESLint
uses: icrawl/action-eslint@v1 uses: icrawl/action-eslint@v1
@ -34,7 +34,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run TSLint - name: Run TSLint
run: npm run lint:typings run: npm run lint:typings
@ -52,7 +52,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Register Problem Matcher - name: Register Problem Matcher
run: echo "##[add-matcher].github/tsc.json" run: echo "##[add-matcher].github/tsc.json"
@ -73,7 +73,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Test documentation - name: Test documentation
run: npm run docs:test run: npm run docs:test

View file

@ -14,7 +14,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run ESLint - name: Run ESLint
uses: icrawl/action-eslint@v1 uses: icrawl/action-eslint@v1
@ -32,7 +32,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run TSLint - name: Run TSLint
run: npm run lint:typings run: npm run lint:typings
@ -50,7 +50,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Register Problem Matcher - name: Register Problem Matcher
run: echo "##[add-matcher].github/tsc.json" run: echo "##[add-matcher].github/tsc.json"
@ -71,7 +71,7 @@ jobs:
node-version: 12 node-version: 12
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Test documentation - name: Test documentation
run: npm run docs:test run: npm run docs:test

View file

@ -25,6 +25,7 @@ export const {
SnowflakeUtil, SnowflakeUtil,
Structures, Structures,
SystemChannelFlags, SystemChannelFlags,
UserFlags,
Util, Util,
version, version,
ChannelManager, ChannelManager,
@ -34,6 +35,7 @@ export const {
GuildMemberManager, GuildMemberManager,
GuildMemberRoleManager, GuildMemberRoleManager,
GuildManager, GuildManager,
ReactionManager,
ReactionUserManager, ReactionUserManager,
MessageManager, MessageManager,
PresenceManager, PresenceManager,
@ -45,9 +47,11 @@ export const {
resolveColor, resolveColor,
resolveString, resolveString,
splitMessage, splitMessage,
Application,
Base, Base,
Activity, Activity,
APIMessage, APIMessage,
BaseGuildEmoji,
CategoryChannel, CategoryChannel,
Channel, Channel,
ClientApplication, ClientApplication,
@ -60,6 +64,7 @@ export const {
GuildChannel, GuildChannel,
GuildEmoji, GuildEmoji,
GuildMember, GuildMember,
GuildPreview,
Integration, Integration,
Invite, Invite,
Message, Message,

1150
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "discord.js", "name": "discord.js",
"version": "12.3.1", "version": "12.4.1",
"description": "A powerful library for interacting with the Discord API", "description": "A powerful library for interacting with the Discord API",
"main": "./src/index", "main": "./src/index",
"types": "./typings/index.d.ts", "types": "./typings/index.d.ts",
@ -60,23 +60,23 @@
"@commitlint/cli": "^11.0.0", "@commitlint/cli": "^11.0.0",
"@commitlint/config-angular": "^11.0.0", "@commitlint/config-angular": "^11.0.0",
"@types/node": "^12.12.6", "@types/node": "^12.12.6",
"@types/ws": "^7.2.6", "@types/ws": "^7.2.7",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"discord.js-docgen": "discordjs/docgen", "discord.js-docgen": "git+https://github.com/discordjs/docgen.git",
"dtslint": "^4.0.0", "dtslint": "^4.0.4",
"eslint": "^7.9.0", "eslint": "^7.11.0",
"eslint-config-prettier": "^6.11.0", "eslint-config-prettier": "^6.13.0",
"eslint-plugin-import": "^2.22.0", "eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4", "eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0", "husky": "^4.3.0",
"jest": "^26.4.2", "jest": "^26.6.0",
"json-filter-loader": "^1.0.0", "json-filter-loader": "^1.0.0",
"lint-staged": "^10.3.0", "lint-staged": "^10.4.2",
"prettier": "^2.1.1", "prettier": "^2.1.2",
"terser-webpack-plugin": "^4.2.0", "terser-webpack-plugin": "^4.2.3",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"typescript": "^4.0.2", "typescript": "^4.0.3",
"webpack": "^4.44.1", "webpack": "^4.44.2",
"webpack-cli": "^3.3.12" "webpack-cli": "^3.3.12"
}, },
"engines": { "engines": {

View file

@ -432,6 +432,13 @@ class Client extends BaseClient {
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) { if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number'); throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
} }
if (
typeof options.messageEditHistoryMaxSize !== 'number' ||
isNaN(options.messageEditHistoryMaxSize) ||
options.messageEditHistoryMaxSize < -1
) {
throw new TypeError('CLIENT_INVALID_OPTION', 'messageEditHistoryMaxSize', 'a number greater than or equal to -1');
}
if (typeof options.fetchAllMembers !== 'boolean') { if (typeof options.fetchAllMembers !== 'boolean') {
throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean'); throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean');
} }

View file

@ -94,7 +94,7 @@ class GenericAction {
const guild = this.client.guilds.cache.get(data.guild_id); const guild = this.client.guilds.cache.get(data.guild_id);
if (guild) { if (guild) {
const member = this.getMember(data.member, guild); const member = this.getMember(data.member, guild);
return member ? member.user : undefined; return member ? member.user : this.getUser(data.member.user);
} }
} }
return this.getUser(data); return this.getUser(data);

View file

@ -5,13 +5,14 @@ const { Events } = require('../../util/Constants');
class GuildEmojiCreateAction extends Action { class GuildEmojiCreateAction extends Action {
handle(guild, createdEmoji) { handle(guild, createdEmoji) {
const already = guild.emojis.cache.has(createdEmoji.id);
const emoji = guild.emojis.add(createdEmoji); const emoji = guild.emojis.add(createdEmoji);
/** /**
* Emitted whenever a custom emoji is created in a guild. * Emitted whenever a custom emoji is created in a guild.
* @event Client#emojiCreate * @event Client#emojiCreate
* @param {GuildEmoji} emoji The emoji that was created * @param {GuildEmoji} emoji The emoji that was created
*/ */
this.client.emit(Events.GUILD_EMOJI_CREATE, emoji); if (!already) this.client.emit(Events.GUILD_EMOJI_CREATE, emoji);
return { emoji }; return { emoji };
} }
} }

View file

@ -9,7 +9,7 @@ class InviteCreateAction extends Action {
const client = this.client; const client = this.client;
const channel = client.channels.cache.get(data.channel_id); const channel = client.channels.cache.get(data.channel_id);
const guild = client.guilds.cache.get(data.guild_id); const guild = client.guilds.cache.get(data.guild_id);
if (!channel && !guild) return false; if (!channel) return false;
const inviteData = Object.assign(data, { channel, guild }); const inviteData = Object.assign(data, { channel, guild });
const invite = new Invite(client, inviteData); const invite = new Invite(client, inviteData);

View file

@ -9,9 +9,9 @@ class MessageUpdateAction extends Action {
const { id, channel_id, guild_id, author, timestamp, type } = data; const { id, channel_id, guild_id, author, timestamp, type } = data;
const message = this.getMessage({ id, channel_id, guild_id, author, timestamp, type }, channel); const message = this.getMessage({ id, channel_id, guild_id, author, timestamp, type }, channel);
if (message) { if (message) {
message.patch(data); const old = message.patch(data);
return { return {
old: message._edits[0], old,
updated: message, updated: message,
}; };
} }

View file

@ -165,7 +165,7 @@ class VoiceConnection extends EventEmitter {
/** /**
* The voice state of this connection * The voice state of this connection
* @type {VoiceState} * @type {?VoiceState}
*/ */
get voice() { get voice() {
return this.channel.guild.voice; return this.channel.guild.voice;
@ -203,8 +203,8 @@ class VoiceConnection extends EventEmitter {
* Set the token and endpoint required to connect to the voice servers. * Set the token and endpoint required to connect to the voice servers.
* @param {string} token The voice token * @param {string} token The voice token
* @param {string} endpoint The voice endpoint * @param {string} endpoint The voice endpoint
* @private
* @returns {void} * @returns {void}
* @private
*/ */
setTokenAndEndpoint(token, endpoint) { setTokenAndEndpoint(token, endpoint) {
this.emit('debug', `Token "${token}" and endpoint "${endpoint}"`); this.emit('debug', `Token "${token}" and endpoint "${endpoint}"`);

View file

@ -56,7 +56,7 @@ class StreamDispatcher extends Writable {
* The broadcast controlling this dispatcher, if any * The broadcast controlling this dispatcher, if any
* @type {?VoiceBroadcast} * @type {?VoiceBroadcast}
*/ */
this.broadcast = this.streams.broadcast; this.broadcast = this.streams.broadcast || null;
this._pausedTime = 0; this._pausedTime = 0;
this._silentPausedTime = 0; this._silentPausedTime = 0;

View file

@ -43,7 +43,7 @@ class WebSocketManager extends EventEmitter {
* The gateway this manager uses * The gateway this manager uses
* @type {?string} * @type {?string}
*/ */
this.gateway = undefined; this.gateway = null;
/** /**
* The amount of shards this manager handles * The amount of shards this manager handles
@ -98,11 +98,11 @@ class WebSocketManager extends EventEmitter {
* The current session limit of the client * The current session limit of the client
* @private * @private
* @type {?Object} * @type {?Object}
* @prop {number} total Total number of identifies available * @property {number} total Total number of identifies available
* @prop {number} remaining Number of identifies remaining * @property {number} remaining Number of identifies remaining
* @prop {number} reset_after Number of milliseconds after which the limit resets * @property {number} reset_after Number of milliseconds after which the limit resets
*/ */
this.sessionStartLimit = undefined; this.sessionStartLimit = null;
} }
/** /**
@ -212,7 +212,7 @@ class WebSocketManager extends EventEmitter {
if (UNRESUMABLE_CLOSE_CODES.includes(event.code)) { if (UNRESUMABLE_CLOSE_CODES.includes(event.code)) {
// These event codes cannot be resumed // These event codes cannot be resumed
shard.sessionID = undefined; shard.sessionID = null;
} }
/** /**

View file

@ -56,10 +56,10 @@ class WebSocketShard extends EventEmitter {
/** /**
* The current session ID of the shard * The current session ID of the shard
* @type {string} * @type {?string}
* @private * @private
*/ */
this.sessionID = undefined; this.sessionID = null;
/** /**
* The previous heartbeat ping of the shard * The previous heartbeat ping of the shard
@ -124,7 +124,7 @@ class WebSocketShard extends EventEmitter {
* @type {?NodeJS.Timeout} * @type {?NodeJS.Timeout}
* @private * @private
*/ */
Object.defineProperty(this, 'helloTimeout', { value: undefined, writable: true }); Object.defineProperty(this, 'helloTimeout', { value: null, writable: true });
/** /**
* If the manager attached its event handlers on the shard * If the manager attached its event handlers on the shard
@ -140,7 +140,7 @@ class WebSocketShard extends EventEmitter {
* @type {?Set<string>} * @type {?Set<string>}
* @private * @private
*/ */
Object.defineProperty(this, 'expectedGuilds', { value: undefined, writable: true }); Object.defineProperty(this, 'expectedGuilds', { value: null, writable: true });
/** /**
* The ready timeout * The ready timeout
@ -148,7 +148,7 @@ class WebSocketShard extends EventEmitter {
* @type {?NodeJS.Timeout} * @type {?NodeJS.Timeout}
* @private * @private
*/ */
Object.defineProperty(this, 'readyTimeout', { value: undefined, writable: true }); Object.defineProperty(this, 'readyTimeout', { value: null, writable: true });
/** /**
* Time when the WebSocket connection was opened * Time when the WebSocket connection was opened
@ -428,7 +428,7 @@ class WebSocketShard extends EventEmitter {
// Reset the sequence // Reset the sequence
this.sequence = -1; this.sequence = -1;
// Reset the session ID as it's invalid // Reset the session ID as it's invalid
this.sessionID = undefined; this.sessionID = null;
// Set the status to reconnecting // Set the status to reconnecting
this.status = Status.RECONNECTING; this.status = Status.RECONNECTING;
// Finally, emit the INVALID_SESSION event // Finally, emit the INVALID_SESSION event
@ -457,7 +457,7 @@ class WebSocketShard extends EventEmitter {
// Step 0. Clear the ready timeout, if it exists // Step 0. Clear the ready timeout, if it exists
if (this.readyTimeout) { if (this.readyTimeout) {
this.manager.client.clearTimeout(this.readyTimeout); this.manager.client.clearTimeout(this.readyTimeout);
this.readyTimeout = undefined; this.readyTimeout = null;
} }
// Step 1. If we don't have any other guilds pending, we are ready // Step 1. If we don't have any other guilds pending, we are ready
if (!this.expectedGuilds.size) { if (!this.expectedGuilds.size) {
@ -480,7 +480,7 @@ class WebSocketShard extends EventEmitter {
this.debug(`Shard did not receive any more guild packets in 15 seconds. this.debug(`Shard did not receive any more guild packets in 15 seconds.
Unavailable guild count: ${this.expectedGuilds.size}`); Unavailable guild count: ${this.expectedGuilds.size}`);
this.readyTimeout = undefined; this.readyTimeout = null;
this.status = Status.READY; this.status = Status.READY;
@ -498,7 +498,7 @@ class WebSocketShard extends EventEmitter {
if (this.helloTimeout) { if (this.helloTimeout) {
this.debug('Clearing the HELLO timeout.'); this.debug('Clearing the HELLO timeout.');
this.manager.client.clearTimeout(this.helloTimeout); this.manager.client.clearTimeout(this.helloTimeout);
this.helloTimeout = undefined; this.helloTimeout = null;
} }
return; return;
} }
@ -519,7 +519,7 @@ class WebSocketShard extends EventEmitter {
if (this.heartbeatInterval) { if (this.heartbeatInterval) {
this.debug('Clearing the heartbeat interval.'); this.debug('Clearing the heartbeat interval.');
this.manager.client.clearInterval(this.heartbeatInterval); this.manager.client.clearInterval(this.heartbeatInterval);
this.heartbeatInterval = undefined; this.heartbeatInterval = null;
} }
return; return;
} }
@ -734,7 +734,7 @@ class WebSocketShard extends EventEmitter {
// Step 5: Reset the sequence and session ID if requested // Step 5: Reset the sequence and session ID if requested
if (reset) { if (reset) {
this.sequence = -1; this.sequence = -1;
this.sessionID = undefined; this.sessionID = null;
} }
// Step 6: reset the ratelimit data // Step 6: reset the ratelimit data

View file

@ -6,6 +6,7 @@ const GuildEmoji = require('../structures/GuildEmoji');
const ReactionEmoji = require('../structures/ReactionEmoji'); const ReactionEmoji = require('../structures/ReactionEmoji');
const Collection = require('../util/Collection'); const Collection = require('../util/Collection');
const DataResolver = require('../util/DataResolver'); const DataResolver = require('../util/DataResolver');
const { parseEmoji } = require('../util/Util');
/** /**
* Manages API methods for GuildEmojis and stores their cache. * Manages API methods for GuildEmojis and stores their cache.
@ -105,6 +106,7 @@ class GuildEmojiManager extends BaseManager {
/** /**
* Data that can be resolved to give an emoji identifier. This can be: * Data that can be resolved to give an emoji identifier. This can be:
* * The unicode representation of an emoji * * The unicode representation of an emoji
* * The `<a:name:id>`, `<:name:id>`, `:name:id` or `a:name:id` emoji identifier string of an emoji
* * An EmojiResolvable * * An EmojiResolvable
* @typedef {string|EmojiResolvable} EmojiIdentifierResolvable * @typedef {string|EmojiResolvable} EmojiIdentifierResolvable
*/ */
@ -119,6 +121,10 @@ class GuildEmojiManager extends BaseManager {
if (emojiResolvable) return emojiResolvable.identifier; if (emojiResolvable) return emojiResolvable.identifier;
if (emoji instanceof ReactionEmoji) return emoji.identifier; if (emoji instanceof ReactionEmoji) return emoji.identifier;
if (typeof emoji === 'string') { if (typeof emoji === 'string') {
const res = parseEmoji(emoji);
if (res && res.name.length) {
emoji = `${res.animated ? 'a:' : ''}${res.name}${res.id ? `:${res.id}` : ''}`;
}
if (!emoji.includes('%')) return encodeURIComponent(emoji); if (!emoji.includes('%')) return encodeURIComponent(emoji);
else return emoji; else return emoji;
} }

View file

@ -5,6 +5,7 @@ const { Error, TypeError, RangeError } = require('../errors');
const GuildMember = require('../structures/GuildMember'); const GuildMember = require('../structures/GuildMember');
const Collection = require('../util/Collection'); const Collection = require('../util/Collection');
const { Events, OPCodes } = require('../util/Constants'); const { Events, OPCodes } = require('../util/Constants');
const SnowflakeUtil = require('../util/Snowflake');
/** /**
* Manages API methods for GuildMembers and stores their cache. * Manages API methods for GuildMembers and stores their cache.
@ -161,19 +162,22 @@ class GuildMemberManager extends BaseManager {
* .then(pruned => console.log(`I just pruned ${pruned} people!`)) * .then(pruned => console.log(`I just pruned ${pruned} people!`))
* .catch(console.error); * .catch(console.error);
*/ */
prune({ days = 7, dry = false, count = true, roles = [], reason } = {}) { prune({ days = 7, dry = false, count: compute_prune_count = true, roles = [], reason } = {}) {
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE'); if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
const query = new URLSearchParams(); const query = { days };
query.set('days', days); const resolvedRoles = [];
query.set('compute_prune_count', count);
for (const role of roles) { for (const role of roles) {
const resolvedRole = this.guild.roles.resolveID(role); const resolvedRole = this.guild.roles.resolveID(role);
if (!resolvedRole) { if (!resolvedRole) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array of Roles or Snowflakes', true)); return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array of Roles or Snowflakes', true));
} }
query.append('include_roles', role); resolvedRoles.push(resolvedRole);
}
if (resolvedRoles.length) {
query.include_roles = dry ? resolvedRoles.join(',') : resolvedRoles;
} }
const endpoint = this.client.api.guilds(this.guild.id).prune; const endpoint = this.client.api.guilds(this.guild.id).prune;
@ -182,13 +186,12 @@ class GuildMemberManager extends BaseManager {
return endpoint.get({ query, reason }).then(data => data.pruned); return endpoint.get({ query, reason }).then(data => data.pruned);
} }
const body = [...query.entries()].reduce((acc, [k, v]) => { return endpoint
if (k === 'include_roles') v = (acc[k] || []).concat(v); .post({
acc[k] = v; data: { ...query, compute_prune_count },
return acc; reason,
}, {}); })
.then(data => data.pruned);
return endpoint.post({ data: body, reason }).then(data => data.pruned);
} }
/** /**
@ -263,7 +266,7 @@ class GuildMemberManager extends BaseManager {
user: user_ids, user: user_ids,
query, query,
time = 120e3, time = 120e3,
nonce = Date.now().toString(16), nonce = SnowflakeUtil.generate(),
force = false, force = false,
} = {}) { } = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View file

@ -44,7 +44,7 @@ class Shard extends EventEmitter {
/** /**
* Arguments for the shard's process executable (only when {@link ShardingManager#mode} is `process`) * Arguments for the shard's process executable (only when {@link ShardingManager#mode} is `process`)
* @type {?string[]} * @type {string[]}
*/ */
this.execArgv = manager.execArgv; this.execArgv = manager.execArgv;

View file

@ -125,7 +125,7 @@ class ShardClientUtil {
} }
/** /**
* Evaluates a script or function on all shards, in the context of the {@link Clients}. * Evaluates a script or function on all shards, in the context of the {@link Client}s.
* @param {string|Function} script JavaScript to run on each shard * @param {string|Function} script JavaScript to run on each shard
* @returns {Promise<Array<*>>} Results of the script execution * @returns {Promise<Array<*>>} Results of the script execution
* @example * @example

View file

@ -4,6 +4,7 @@ const Util = require('../util/Util');
/** /**
* Represents a data model that is identifiable by a Snowflake (i.e. Discord API data models). * Represents a data model that is identifiable by a Snowflake (i.e. Discord API data models).
* @abstract
*/ */
class Base { class Base {
constructor(client) { constructor(client) {

View file

@ -5,6 +5,7 @@ const Emoji = require('./Emoji');
/** /**
* Parent class for {@link GuildEmoji} and {@link GuildPreviewEmoji}. * Parent class for {@link GuildEmoji} and {@link GuildPreviewEmoji}.
* @extends {Emoji} * @extends {Emoji}
* @abstract
*/ */
class BaseGuildEmoji extends Emoji { class BaseGuildEmoji extends Emoji {
constructor(client, data, guild) { constructor(client, data, guild) {
@ -16,6 +17,10 @@ class BaseGuildEmoji extends Emoji {
*/ */
this.guild = guild; this.guild = guild;
this.requireColons = null;
this.managed = null;
this.available = null;
/** /**
* Array of role ids this emoji is active for * Array of role ids this emoji is active for
* @name BaseGuildEmoji#_roles * @name BaseGuildEmoji#_roles
@ -30,26 +35,29 @@ class BaseGuildEmoji extends Emoji {
_patch(data) { _patch(data) {
if (data.name) this.name = data.name; if (data.name) this.name = data.name;
/** if (typeof data.require_colons !== 'undefined') {
* Whether or not this emoji requires colons surrounding it /**
* @type {?boolean} * Whether or not this emoji requires colons surrounding it
* @name GuildEmoji#requiresColons * @type {?boolean}
*/ */
if (typeof data.require_colons !== 'undefined') this.requiresColons = data.require_colons; this.requiresColons = data.require_colons;
}
/** if (typeof data.managed !== 'undefined') {
* Whether this emoji is managed by an external service /**
* @type {?boolean} * Whether this emoji is managed by an external service
* @name GuildEmoji#managed * @type {?boolean}
*/ */
if (typeof data.managed !== 'undefined') this.managed = data.managed; this.managed = data.managed;
}
/** if (typeof data.available !== 'undefined') {
* Whether this emoji is available /**
* @type {?boolean} * Whether this emoji is available
* @name GuildEmoji#available * @type {?boolean}
*/ */
if (typeof data.available !== 'undefined') this.available = data.available; this.available = data.available;
}
if (data.roles) this._roles = data.roles; if (data.roles) this._roles = data.roles;
} }

View file

@ -7,6 +7,7 @@ const Snowflake = require('../util/Snowflake');
/** /**
* Represents any channel on Discord. * Represents any channel on Discord.
* @extends {Base} * @extends {Base}
* @abstract
*/ */
class Channel extends Base { class Channel extends Base {
constructor(client, data) { constructor(client, data) {

View file

@ -94,11 +94,9 @@ class ClientUser extends Structures.get('User') {
* @property {PresenceStatusData} [status] Status of the user * @property {PresenceStatusData} [status] Status of the user
* @property {boolean} [afk] Whether the user is AFK * @property {boolean} [afk] Whether the user is AFK
* @property {Object} [activity] Activity the user is playing * @property {Object} [activity] Activity the user is playing
* @property {Object|string} [activity.application] An application object or application id
* @property {string} [activity.application.id] The id of the application
* @property {string} [activity.name] Name of the activity * @property {string} [activity.name] Name of the activity
* @property {ActivityType|number} [activity.type] Type of the activity * @property {ActivityType|number} [activity.type] Type of the activity
* @property {string} [activity.url] Stream url * @property {string} [activity.url] Twitch / YouTube stream URL
* @property {?number|number[]} [shardID] Shard Id(s) to have the activity set on * @property {?number|number[]} [shardID] Shard Id(s) to have the activity set on
*/ */
@ -141,10 +139,10 @@ class ClientUser extends Structures.get('User') {
} }
/** /**
* Options for setting an activity * Options for setting an activity.
* @typedef ActivityOptions * @typedef ActivityOptions
* @type {Object} * @type {Object}
* @property {string} [url] Twitch stream URL * @property {string} [url] Twitch / YouTube stream URL
* @property {ActivityType|number} [type] Type of the activity * @property {ActivityType|number} [type] Type of the activity
* @property {?number|number[]} [shardID] Shard Id(s) to have the activity set on * @property {?number|number[]} [shardID] Shard Id(s) to have the activity set on
*/ */

View file

@ -231,36 +231,38 @@ class Guild extends Base {
*/ */
this.premiumTier = data.premium_tier; this.premiumTier = data.premium_tier;
/**
* The total number of boosts for this server
* @type {?number}
* @name Guild#premiumSubscriptionCount
*/
if (typeof data.premium_subscription_count !== 'undefined') { if (typeof data.premium_subscription_count !== 'undefined') {
/**
* The total number of boosts for this server
* @type {?number}
*/
this.premiumSubscriptionCount = data.premium_subscription_count; this.premiumSubscriptionCount = data.premium_subscription_count;
} }
/** if (typeof data.widget_enabled !== 'undefined') {
* Whether widget images are enabled on this guild /**
* @type {?boolean} * Whether widget images are enabled on this guild
* @name Guild#widgetEnabled * @type {?boolean}
*/ */
if (typeof data.widget_enabled !== 'undefined') this.widgetEnabled = data.widget_enabled; this.widgetEnabled = data.widget_enabled;
}
/** if (typeof data.widget_channel_id !== 'undefined') {
* The widget channel ID, if enabled /**
* @type {?string} * The widget channel ID, if enabled
* @name Guild#widgetChannelID * @type {?string}
*/ */
if (typeof data.widget_channel_id !== 'undefined') this.widgetChannelID = data.widget_channel_id; this.widgetChannelID = data.widget_channel_id;
}
/** if (typeof data.embed_channel_id !== 'undefined') {
* The embed channel ID, if enabled /**
* @type {?string} * The embed channel ID, if enabled
* @name Guild#embedChannelID * @type {?string}
* @deprecated * @deprecated
*/ */
if (typeof data.embed_channel_id !== 'undefined') this.embedChannelID = data.embed_channel_id; this.embedChannelID = data.embed_channel_id;
}
/** /**
* The verification level of the guild * The verification level of the guild
@ -299,40 +301,47 @@ class Guild extends Base {
*/ */
this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze(); this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze();
/** if (typeof data.max_members !== 'undefined') {
* The maximum amount of members the guild can have /**
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info> * The maximum amount of members the guild can have
* @type {?number} * @type {?number}
* @name Guild#maximumMembers */
*/ this.maximumMembers = data.max_members;
if (typeof data.max_members !== 'undefined') this.maximumMembers = data.max_members || 250000; } else if (typeof this.maximumMembers === 'undefined') {
this.maximumMembers = null;
/** }
* The maximum amount of presences the guild can have
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info> if (typeof data.max_presences !== 'undefined') {
* @type {?number} /**
* @name Guild#maximumPresences * The maximum amount of presences the guild can have
*/ * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
if (typeof data.max_presences !== 'undefined') this.maximumPresences = data.max_presences || 25000; * @type {?number}
*/
/** this.maximumPresences = data.max_presences || 25000;
* The approximate amount of members the guild has } else if (typeof this.maximumPresences === 'undefined') {
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info> this.maximumPresences = null;
* @type {?number} }
* @name Guild#approximateMemberCount
*/ if (typeof data.approximate_member_count !== 'undefined') {
if (typeof data.approximate_member_count !== 'undefined') { /**
this.approximateMemberCount = data.approximate_member_count; * The approximate amount of members the guild has
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
* @type {?number}
*/
this.approximateMemberCount = data.approximate_member_count;
} else if (typeof this.approximateMemberCount === 'undefined') {
this.approximateMemberCount = null;
} }
/**
* The approximate amount of presences the guild has
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
* @type {?number}
* @name Guild#approximatePresenceCount
*/
if (typeof data.approximate_presence_count !== 'undefined') { if (typeof data.approximate_presence_count !== 'undefined') {
/**
* The approximate amount of presences the guild has
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
* @type {?number}
*/
this.approximatePresenceCount = data.approximate_presence_count; this.approximatePresenceCount = data.approximate_presence_count;
} else if (typeof this.approximatePresenceCount === 'undefined') {
this.approximatePresenceCount = null;
} }
/** /**

View file

@ -24,7 +24,7 @@ const Util = require('../util/Util');
/** /**
* Key mirror of all available audit log targets. * Key mirror of all available audit log targets.
* @name GuildAuditLogs.Targets * @name GuildAuditLogs.Targets
* @type {AuditLogTargetType} * @type {Object<string, string>}
*/ */
const Targets = { const Targets = {
ALL: 'ALL', ALL: 'ALL',
@ -84,7 +84,7 @@ const Targets = {
/** /**
* All available actions keyed under their names to their numeric values. * All available actions keyed under their names to their numeric values.
* @name GuildAuditLogs.Actions * @name GuildAuditLogs.Actions
* @type {AuditLogAction} * @type {Object<string, number>}
*/ */
const Actions = { const Actions = {
ALL: null, ALL: null,

View file

@ -17,6 +17,7 @@ const Util = require('../util/Util');
* - {@link NewsChannel} * - {@link NewsChannel}
* - {@link StoreChannel} * - {@link StoreChannel}
* @extends {Channel} * @extends {Channel}
* @abstract
*/ */
class GuildChannel extends Channel { class GuildChannel extends Channel {
/** /**
@ -52,7 +53,7 @@ class GuildChannel extends Channel {
* The ID of the category parent of this channel * The ID of the category parent of this channel
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.parentID = data.parent_id; this.parentID = data.parent_id || null;
/** /**
* A map of permission overwrites in this channel for roles and users * A map of permission overwrites in this channel for roles and users
@ -298,7 +299,7 @@ class GuildChannel extends Channel {
* @property {boolean} [nsfw] Whether the channel is NSFW * @property {boolean} [nsfw] Whether the channel is NSFW
* @property {number} [bitrate] The bitrate of the voice channel * @property {number} [bitrate] The bitrate of the voice channel
* @property {number} [userLimit] The user limit of the voice channel * @property {number} [userLimit] The user limit of the voice channel
* @property {Snowflake} [parentID] The parent ID of the channel * @property {?Snowflake} [parentID] The parent ID of the channel
* @property {boolean} [lockPermissions] * @property {boolean} [lockPermissions]
* Lock the permissions of the channel to what the parent's permissions are * Lock the permissions of the channel to what the parent's permissions are
* @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites] * @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
@ -412,7 +413,7 @@ class GuildChannel extends Channel {
/** /**
* Sets a new topic for the guild channel. * Sets a new topic for the guild channel.
* @param {string} topic The new topic for the guild channel * @param {?string} topic The new topic for the guild channel
* @param {string} [reason] Reason for changing the guild channel's topic * @param {string} [reason] Reason for changing the guild channel's topic
* @returns {Promise<GuildChannel>} * @returns {Promise<GuildChannel>}
* @example * @example

View file

@ -61,7 +61,6 @@ class GuildMember extends Base {
/** /**
* The nickname of this member, if they have one * The nickname of this member, if they have one
* @type {?string} * @type {?string}
* @name GuildMember#nickname
*/ */
this.nickname = null; this.nickname = null;
@ -74,7 +73,6 @@ class GuildMember extends Base {
/** /**
* The user that this guild member instance represents * The user that this guild member instance represents
* @type {User} * @type {User}
* @name GuildMember#user
*/ */
this.user = this.client.users.add(data.user, true); this.user = this.client.users.add(data.user, true);
} }
@ -269,7 +267,8 @@ class GuildMember extends Base {
*/ */
hasPermission(permission, { checkAdmin = true, checkOwner = true } = {}) { hasPermission(permission, { checkAdmin = true, checkOwner = true } = {}) {
if (checkOwner && this.user.id === this.guild.ownerID) return true; if (checkOwner && this.user.id === this.guild.ownerID) return true;
return this.roles.cache.some(r => r.permissions.has(permission, checkAdmin)); const permissions = new Permissions(this.roles.cache.map(role => role.permissions));
return permissions.has(permission, checkAdmin);
} }
/** /**

View file

@ -75,7 +75,7 @@ class GuildPreview extends Base {
* The description for this guild * The description for this guild
* @type {?string} * @type {?string}
*/ */
this.description = data.description; this.description = data.description || null;
if (!this.emojis) { if (!this.emojis) {
/** /**

View file

@ -65,6 +65,8 @@ class Integration extends Base {
* @type {?User} * @type {?User}
*/ */
this.user = this.client.users.add(data.user); this.user = this.client.users.add(data.user);
} else {
this.user = null;
} }
/** /**

View file

@ -239,13 +239,18 @@ class Message extends Base {
} }
/** /**
* Updates the message. * Updates the message and returns the old message.
* @param {Object} data Raw Discord message update data * @param {Object} data Raw Discord message update data
* @returns {Message}
* @private * @private
*/ */
patch(data) { patch(data) {
const clone = this._clone(); const clone = this._clone();
this._edits.unshift(clone); const { messageEditHistoryMaxSize } = this.client.options;
if (messageEditHistoryMaxSize !== 0) {
const editsLimit = messageEditHistoryMaxSize === -1 ? Infinity : messageEditHistoryMaxSize;
if (this._edits.unshift(clone) > editsLimit) this._edits.pop();
}
if ('edited_timestamp' in data) this.editedTimestamp = new Date(data.edited_timestamp).getTime(); if ('edited_timestamp' in data) this.editedTimestamp = new Date(data.edited_timestamp).getTime();
if ('content' in data) this.content = data.content; if ('content' in data) this.content = data.content;
@ -272,6 +277,8 @@ class Message extends Base {
); );
this.flags = new MessageFlags('flags' in data ? data.flags : 0).freeze(); this.flags = new MessageFlags('flags' in data ? data.flags : 0).freeze();
return clone;
} }
/** /**
@ -434,6 +441,23 @@ class Message extends Base {
return referenceChannel.messages.resolve(this.reference.messageID); return referenceChannel.messages.resolve(this.reference.messageID);
} }
/**
* Whether the message is crosspostable by the client user
* @type {boolean}
* @readonly
*/
get crosspostable() {
return (
this.channel.type === 'news' &&
!this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) &&
this.type === 'DEFAULT' &&
this.channel.viewable &&
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.SEND_MESSAGES) &&
(this.author.id === this.client.user.id ||
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES))
);
}
/** /**
* Options that can be passed into editMessage. * Options that can be passed into editMessage.
* @typedef {Object} MessageEditOptions * @typedef {Object} MessageEditOptions

View file

@ -29,37 +29,37 @@ class MessageEmbed {
* * `link` - a link embed * * `link` - a link embed
* @type {string} * @type {string}
*/ */
this.type = data.type; this.type = data.type || 'rich';
/** /**
* The title of this embed * The title of this embed
* @type {?string} * @type {?string}
*/ */
this.title = data.title; this.title = 'title' in data ? data.title : null;
/** /**
* The description of this embed * The description of this embed
* @type {?string} * @type {?string}
*/ */
this.description = data.description; this.description = 'description' in data ? data.description : null;
/** /**
* The URL of this embed * The URL of this embed
* @type {?string} * @type {?string}
*/ */
this.url = data.url; this.url = 'url' in data ? data.url : null;
/** /**
* The color of this embed * The color of this embed
* @type {?number} * @type {?number}
*/ */
this.color = Util.resolveColor(data.color); this.color = 'color' in data ? Util.resolveColor(data.color) : null;
/** /**
* The timestamp of this embed * The timestamp of this embed
* @type {?number} * @type {?number}
*/ */
this.timestamp = data.timestamp ? new Date(data.timestamp).getTime() : null; this.timestamp = 'timestamp' in data ? new Date(data.timestamp).getTime() : null;
/** /**
* Represents a field of a MessageEmbed * Represents a field of a MessageEmbed
@ -331,7 +331,7 @@ class MessageEmbed {
*/ */
setFooter(text, iconURL) { setFooter(text, iconURL) {
text = Util.resolveString(text); text = Util.resolveString(text);
this.footer = { text, iconURL, proxyIconURL: undefined }; this.footer = { text, iconURL };
return this; return this;
} }

View file

@ -46,13 +46,14 @@ class MessageReaction {
} }
_patch(data) { _patch(data) {
/**
* The number of people that have given the same reaction
* @type {?number}
* @name MessageReaction#count
*/
// eslint-disable-next-line eqeqeq // eslint-disable-next-line eqeqeq
if (this.count == undefined) this.count = data.count; if (this.count == undefined) {
/**
* The number of people that have given the same reaction
* @type {?number}
*/
this.count = data.count;
}
} }
/** /**

View file

@ -184,8 +184,8 @@ class Activity {
/** /**
* Timestamps for the activity * Timestamps for the activity
* @type {?Object} * @type {?Object}
* @prop {?Date} start When the activity started * @property {?Date} start When the activity started
* @prop {?Date} end When the activity will end * @property {?Date} end When the activity will end
*/ */
this.timestamps = data.timestamps this.timestamps = data.timestamps
? { ? {
@ -197,8 +197,8 @@ class Activity {
/** /**
* Party of the activity * Party of the activity
* @type {?Object} * @type {?Object}
* @prop {?string} id ID of the party * @property {?string} id ID of the party
* @prop {number[]} size Size of the party as `[current, max]` * @property {number[]} size Size of the party as `[current, max]`
*/ */
this.party = data.party || null; this.party = data.party || null;

View file

@ -27,6 +27,10 @@ class User extends Base {
*/ */
this.id = data.id; this.id = data.id;
this.system = null;
this.locale = null;
this.flags = null;
this._patch(data); this._patch(data);
} }
@ -35,7 +39,6 @@ class User extends Base {
/** /**
* The username of the user * The username of the user
* @type {?string} * @type {?string}
* @name User#username
*/ */
this.username = data.username; this.username = data.username;
} else if (typeof this.username !== 'string') { } else if (typeof this.username !== 'string') {
@ -45,7 +48,6 @@ class User extends Base {
/** /**
* Whether or not the user is a bot * Whether or not the user is a bot
* @type {boolean} * @type {boolean}
* @name User#bot
*/ */
this.bot = Boolean(data.bot); this.bot = Boolean(data.bot);
@ -53,7 +55,6 @@ class User extends Base {
/** /**
* A discriminator based on username for the user * A discriminator based on username for the user
* @type {?string} * @type {?string}
* @name User#discriminator
*/ */
this.discriminator = data.discriminator; this.discriminator = data.discriminator;
} else if (typeof this.discriminator !== 'string') { } else if (typeof this.discriminator !== 'string') {
@ -64,7 +65,6 @@ class User extends Base {
/** /**
* The ID of the user's avatar * The ID of the user's avatar
* @type {?string} * @type {?string}
* @name User#avatar
*/ */
this.avatar = data.avatar; this.avatar = data.avatar;
} else if (typeof this.avatar !== 'string') { } else if (typeof this.avatar !== 'string') {
@ -75,7 +75,6 @@ class User extends Base {
/** /**
* Whether the user is an Official Discord System user (part of the urgent message system) * Whether the user is an Official Discord System user (part of the urgent message system)
* @type {?boolean} * @type {?boolean}
* @name User#system
*/ */
this.system = Boolean(data.system); this.system = Boolean(data.system);
} }
@ -84,7 +83,6 @@ class User extends Base {
/** /**
* The locale of the user's client (ISO 639-1) * The locale of the user's client (ISO 639-1)
* @type {?string} * @type {?string}
* @name User#locale
*/ */
this.locale = data.locale; this.locale = data.locale;
} }
@ -93,7 +91,6 @@ class User extends Base {
/** /**
* The flags for this user * The flags for this user
* @type {?UserFlags} * @type {?UserFlags}
* @name User#flags
*/ */
this.flags = new UserFlags(data.public_flags); this.flags = new UserFlags(data.public_flags);
} }

View file

@ -29,7 +29,6 @@ class VoiceChannel extends GuildChannel {
/** /**
* The members in this voice channel * The members in this voice channel
* @type {Collection<Snowflake, GuildMember>} * @type {Collection<Snowflake, GuildMember>}
* @name VoiceChannel#members
* @readonly * @readonly
*/ */
get members() { get members() {

View file

@ -32,32 +32,32 @@ class VoiceState extends Base {
* Whether this member is deafened server-wide * Whether this member is deafened server-wide
* @type {?boolean} * @type {?boolean}
*/ */
this.serverDeaf = data.deaf; this.serverDeaf = 'deaf' in data ? data.deaf : null;
/** /**
* Whether this member is muted server-wide * Whether this member is muted server-wide
* @type {?boolean} * @type {?boolean}
*/ */
this.serverMute = data.mute; this.serverMute = 'mute' in data ? data.mute : null;
/** /**
* Whether this member is self-deafened * Whether this member is self-deafened
* @type {?boolean} * @type {?boolean}
*/ */
this.selfDeaf = data.self_deaf; this.selfDeaf = 'self_deaf' in data ? data.self_deaf : null;
/** /**
* Whether this member is self-muted * Whether this member is self-muted
* @type {?boolean} * @type {?boolean}
*/ */
this.selfMute = data.self_mute; this.selfMute = 'self_mute' in data ? data.self_mute : null;
/** /**
* Whether this member's camera is enabled * Whether this member's camera is enabled
* @type {boolean} * @type {?boolean}
*/ */
this.selfVideo = data.self_video; this.selfVideo = 'self_video' in data ? data.self_video : null;
/** /**
* The session ID of this member's connection * The session ID of this member's connection
* @type {?string} * @type {?string}
*/ */
this.sessionID = data.session_id; this.sessionID = 'session_id' in data ? data.session_id : null;
/** /**
* Whether this member is streaming using "Go Live" * Whether this member is streaming using "Go Live"
* @type {boolean} * @type {boolean}
@ -67,7 +67,7 @@ class VoiceState extends Base {
* The ID of the voice channel that this member is in * The ID of the voice channel that this member is in
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.channelID = data.channel_id; this.channelID = data.channel_id || null;
return this; return this;
} }

View file

@ -19,6 +19,8 @@ const browser = (exports.browser = typeof window !== 'undefined');
* sweepable (in seconds, 0 for forever) * sweepable (in seconds, 0 for forever)
* @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than * @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
* the message cache lifetime (in seconds, 0 for never) * the message cache lifetime (in seconds, 0 for never)
* @property {number} [messageEditHistoryMaxSize=-1] Maximum number of previous versions to hold for an edited message
* (-1 or Infinity for unlimited - don't do this without sweeping, otherwise memory usage may climb indefinitely.)
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as * @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as
* upon joining a guild (should be avoided whenever possible) * upon joining a guild (should be avoided whenever possible)
* @property {DisableMentionType} [disableMentions='none'] Default value for {@link MessageOptions#disableMentions} * @property {DisableMentionType} [disableMentions='none'] Default value for {@link MessageOptions#disableMentions}
@ -43,6 +45,7 @@ exports.DefaultOptions = {
messageCacheMaxSize: 200, messageCacheMaxSize: 200,
messageCacheLifetime: 0, messageCacheLifetime: 0,
messageSweepInterval: 0, messageSweepInterval: 0,
messageEditHistoryMaxSize: -1,
fetchAllMembers: false, fetchAllMembers: false,
disableMentions: 'none', disableMentions: 'none',
partials: [], partials: [],

77
typings/index.d.ts vendored
View file

@ -29,6 +29,7 @@ declare module 'discord.js' {
public createdTimestamp: number; public createdTimestamp: number;
public details: string | null; public details: string | null;
public emoji: Emoji | null; public emoji: Emoji | null;
public flags: Readonly<ActivityFlags>;
public name: string; public name: string;
public party: { public party: {
id: string | null; id: string | null;
@ -141,13 +142,13 @@ declare module 'discord.js' {
constructor(client: Client, data: object, guild: Guild); constructor(client: Client, data: object, guild: Guild);
private _roles: string[]; private _roles: string[];
public available?: boolean; public available: boolean | null;
public readonly createdAt: Date; public readonly createdAt: Date;
public readonly createdTimestamp: number; public readonly createdTimestamp: number;
public guild: Guild | GuildPreview; public guild: Guild | GuildPreview;
public id: Snowflake; public id: Snowflake;
public managed?: boolean; public managed: boolean | null;
public requiresColons?: boolean; public requiresColons: boolean | null;
} }
class BroadcastDispatcher extends VolumeMixin(StreamDispatcher) { class BroadcastDispatcher extends VolumeMixin(StreamDispatcher) {
@ -624,8 +625,8 @@ declare module 'discord.js' {
public afkChannelID: Snowflake | null; public afkChannelID: Snowflake | null;
public afkTimeout: number; public afkTimeout: number;
public applicationID: Snowflake | null; public applicationID: Snowflake | null;
public approximateMemberCount?: number; public approximateMemberCount: number | null;
public approximatePresenceCount?: number; public approximatePresenceCount: number | null;
public available: boolean; public available: boolean;
public banner: string | null; public banner: string | null;
public channels: GuildChannelManager; public channels: GuildChannelManager;
@ -817,11 +818,11 @@ declare module 'discord.js' {
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<Permissions> | null; public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<Permissions> | null;
public setName(name: string, reason?: string): Promise<this>; public setName(name: string, reason?: string): Promise<this>;
public setParent( public setParent(
channel: CategoryChannel | Snowflake, channel: CategoryChannel | Snowflake | null,
options?: { lockPermissions?: boolean; reason?: string }, options?: { lockPermissions?: boolean; reason?: string },
): Promise<this>; ): Promise<this>;
public setPosition(position: number, options?: { relative?: boolean; reason?: string }): Promise<this>; public setPosition(position: number, options?: { relative?: boolean; reason?: string }): Promise<this>;
public setTopic(topic: string, reason?: string): Promise<this>; public setTopic(topic: string | null, reason?: string): Promise<this>;
public updateOverwrite( public updateOverwrite(
userOrRole: RoleResolvable | UserResolvable, userOrRole: RoleResolvable | UserResolvable,
options: PermissionOverwriteOption, options: PermissionOverwriteOption,
@ -887,7 +888,7 @@ declare module 'discord.js' {
constructor(client: Client, data: object); constructor(client: Client, data: object);
public approximateMemberCount: number; public approximateMemberCount: number;
public approximatePresenceCount: number; public approximatePresenceCount: number;
public description?: string; public description: string | null;
public discoverySplash: string | null; public discoverySplash: string | null;
public emojis: Collection<Snowflake, GuildPreviewEmoji>; public emojis: Collection<Snowflake, GuildPreviewEmoji>;
public features: GuildFeatures[]; public features: GuildFeatures[];
@ -931,7 +932,7 @@ declare module 'discord.js' {
public syncedAt: number; public syncedAt: number;
public syncing: boolean; public syncing: boolean;
public type: string; public type: string;
public user?: User; public user: User | null;
public delete(reason?: string): Promise<Integration>; public delete(reason?: string): Promise<Integration>;
public edit(data: IntegrationEditData, reason?: string): Promise<Integration>; public edit(data: IntegrationEditData, reason?: string): Promise<Integration>;
public sync(): Promise<Integration>; public sync(): Promise<Integration>;
@ -977,7 +978,7 @@ declare module 'discord.js' {
export class Message extends Base { export class Message extends Base {
constructor(client: Client, data: object, channel: TextChannel | DMChannel | NewsChannel); constructor(client: Client, data: object, channel: TextChannel | DMChannel | NewsChannel);
private _edits: Message[]; private _edits: Message[];
private patch(data: object): void; private patch(data: object): Message;
public activity: MessageActivity | null; public activity: MessageActivity | null;
public application: ClientApplication | null; public application: ClientApplication | null;
@ -1054,7 +1055,7 @@ declare module 'discord.js' {
public attachment: BufferResolvable | Stream; public attachment: BufferResolvable | Stream;
public height: number | null; public height: number | null;
public id: Snowflake; public id: Snowflake;
public name?: string; public name: string | null;
public proxyURL: string; public proxyURL: string;
public size: number; public size: number;
public readonly spoiler: boolean; public readonly spoiler: boolean;
@ -1082,9 +1083,9 @@ declare module 'discord.js' {
export class MessageEmbed { export class MessageEmbed {
constructor(data?: MessageEmbed | MessageEmbedOptions); constructor(data?: MessageEmbed | MessageEmbedOptions);
public author: MessageEmbedAuthor | null; public author: MessageEmbedAuthor | null;
public color?: number; public color: number | null;
public readonly createdAt: Date | null; public readonly createdAt: Date | null;
public description?: string; public description: string | null;
public fields: EmbedField[]; public fields: EmbedField[];
public files: (MessageAttachment | string | FileOptions)[]; public files: (MessageAttachment | string | FileOptions)[];
public footer: MessageEmbedFooter | null; public footer: MessageEmbedFooter | null;
@ -1094,9 +1095,9 @@ declare module 'discord.js' {
public provider: MessageEmbedProvider | null; public provider: MessageEmbedProvider | null;
public thumbnail: MessageEmbedThumbnail | null; public thumbnail: MessageEmbedThumbnail | null;
public timestamp: number | null; public timestamp: number | null;
public title?: string; public title: string | null;
public type: string; public type: string;
public url?: string; public url: string | null;
public readonly video: MessageEmbedVideo | null; public readonly video: MessageEmbedVideo | null;
public addField(name: StringResolvable, value: StringResolvable, inline?: boolean): this; public addField(name: StringResolvable, value: StringResolvable, inline?: boolean): this;
public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this; public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
@ -1232,7 +1233,6 @@ declare module 'discord.js' {
constructor(client: Client, data?: object); constructor(client: Client, data?: object);
public activities: Activity[]; public activities: Activity[];
public clientStatus: ClientPresenceStatusData | null; public clientStatus: ClientPresenceStatusData | null;
public flags: Readonly<ActivityFlags>;
public guild: Guild | null; public guild: Guild | null;
public readonly member: GuildMember | null; public readonly member: GuildMember | null;
public status: PresenceStatus; public status: PresenceStatus;
@ -1541,13 +1541,13 @@ declare module 'discord.js' {
public discriminator: string; public discriminator: string;
public readonly defaultAvatarURL: string; public readonly defaultAvatarURL: string;
public readonly dmChannel: DMChannel | null; public readonly dmChannel: DMChannel | null;
public flags?: Readonly<UserFlags>; public flags: Readonly<UserFlags> | null;
public id: Snowflake; public id: Snowflake;
public lastMessageID: Snowflake | null; public lastMessageID: Snowflake | null;
public locale?: string; public locale: string | null;
public readonly partial: false; public readonly partial: false;
public readonly presence: Presence; public readonly presence: Presence;
public system?: boolean; public system: boolean | null;
public readonly tag: string; public readonly tag: string;
public username: string; public username: string;
public avatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null; public avatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
@ -1614,7 +1614,7 @@ declare module 'discord.js' {
constructor(client: Client); constructor(client: Client);
public client: Client; public client: Client;
public subscribers: StreamDispatcher[]; public subscribers: StreamDispatcher[];
public readonly dispatcher?: BroadcastDispatcher; public readonly dispatcher: BroadcastDispatcher | null;
public play(input: string | Readable, options?: StreamOptions): BroadcastDispatcher; public play(input: string | Readable, options?: StreamOptions): BroadcastDispatcher;
public end(): void; public end(): void;
@ -1670,7 +1670,7 @@ declare module 'discord.js' {
public receiver: VoiceReceiver; public receiver: VoiceReceiver;
public speaking: Readonly<Speaking>; public speaking: Readonly<Speaking>;
public status: VoiceStatus; public status: VoiceStatus;
public readonly voice: VoiceState; public readonly voice: VoiceState | null;
public voiceManager: ClientVoiceManager; public voiceManager: ClientVoiceManager;
public disconnect(): void; public disconnect(): void;
public play(input: VoiceBroadcast | Readable | string, options?: StreamOptions): StreamDispatcher; public play(input: VoiceBroadcast | Readable | string, options?: StreamOptions): StreamDispatcher;
@ -1722,18 +1722,18 @@ declare module 'discord.js' {
export class VoiceState extends Base { export class VoiceState extends Base {
constructor(guild: Guild, data: object); constructor(guild: Guild, data: object);
public readonly channel: VoiceChannel | null; public readonly channel: VoiceChannel | null;
public channelID?: Snowflake; public channelID: Snowflake | null;
public readonly connection: VoiceConnection | null; public readonly connection: VoiceConnection | null;
public readonly deaf?: boolean; public readonly deaf: boolean | null;
public guild: Guild; public guild: Guild;
public id: Snowflake; public id: Snowflake;
public readonly member: GuildMember | null; public readonly member: GuildMember | null;
public readonly mute?: boolean; public readonly mute: boolean | null;
public selfDeaf?: boolean; public selfDeaf: boolean | null;
public selfMute?: boolean; public selfMute: boolean | null;
public serverDeaf?: boolean; public serverDeaf: boolean | null;
public serverMute?: boolean; public serverMute: boolean | null;
public sessionID?: string; public sessionID: string | null;
public streaming: boolean; public streaming: boolean;
public selfVideo: boolean; public selfVideo: boolean;
public readonly speaking: boolean | null; public readonly speaking: boolean | null;
@ -1787,10 +1787,10 @@ declare module 'discord.js' {
private packetQueue: object[]; private packetQueue: object[];
private destroyed: boolean; private destroyed: boolean;
private reconnecting: boolean; private reconnecting: boolean;
private sessionStartLimit?: { total: number; remaining: number; reset_after: number }; private sessionStartLimit: { total: number; remaining: number; reset_after: number } | null;
public readonly client: Client; public readonly client: Client;
public gateway?: string; public gateway: string | null;
public shards: Collection<number, WebSocketShard>; public shards: Collection<number, WebSocketShard>;
public status: Status; public status: Status;
public readonly ping: number; public readonly ping: number;
@ -1814,15 +1814,15 @@ declare module 'discord.js' {
constructor(manager: WebSocketManager, id: number); constructor(manager: WebSocketManager, id: number);
private sequence: number; private sequence: number;
private closeSequence: number; private closeSequence: number;
private sessionID?: string; private sessionID: string | null;
private lastPingTimestamp: number; private lastPingTimestamp: number;
private lastHeartbeatAcked: boolean; private lastHeartbeatAcked: boolean;
private ratelimit: { queue: object[]; total: number; remaining: number; time: 60e3; timer: NodeJS.Timeout | null }; private ratelimit: { queue: object[]; total: number; remaining: number; time: 60e3; timer: NodeJS.Timeout | null };
private connection: WebSocket | null; private connection: WebSocket | null;
private helloTimeout: NodeJS.Timeout | undefined; private helloTimeout: NodeJS.Timeout | null;
private eventsAttached: boolean; private eventsAttached: boolean;
private expectedGuilds: Set<Snowflake> | undefined; private expectedGuilds: Set<Snowflake> | null;
private readyTimeout: NodeJS.Timeout | undefined; private readyTimeout: NodeJS.Timeout | null;
public manager: WebSocketManager; public manager: WebSocketManager;
public id: number; public id: number;
@ -2072,7 +2072,7 @@ declare module 'discord.js' {
interface TextBasedChannelFields extends PartialTextBasedChannelFields { interface TextBasedChannelFields extends PartialTextBasedChannelFields {
_typing: Map<string, TypingData>; _typing: Map<string, TypingData>;
lastPinTimestamp: number | null; lastPinTimestamp: number | null;
readonly lastPinAt: Date; readonly lastPinAt: Date | null;
typing: boolean; typing: boolean;
typingCount: number; typingCount: number;
awaitMessages(filter: CollectorFilter, options?: AwaitMessagesOptions): Promise<Collection<Snowflake, Message>>; awaitMessages(filter: CollectorFilter, options?: AwaitMessagesOptions): Promise<Collection<Snowflake, Message>>;
@ -2235,7 +2235,7 @@ declare module 'discord.js' {
nsfw?: boolean; nsfw?: boolean;
bitrate?: number; bitrate?: number;
userLimit?: number; userLimit?: number;
parentID?: Snowflake; parentID?: Snowflake | null;
rateLimitPerUser?: number; rateLimitPerUser?: number;
lockPermissions?: boolean; lockPermissions?: boolean;
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>; permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
@ -2318,6 +2318,7 @@ declare module 'discord.js' {
messageCacheMaxSize?: number; messageCacheMaxSize?: number;
messageCacheLifetime?: number; messageCacheLifetime?: number;
messageSweepInterval?: number; messageSweepInterval?: number;
messageEditHistoryMaxSize?: number;
fetchAllMembers?: boolean; fetchAllMembers?: boolean;
disableMentions?: 'none' | 'all' | 'everyone'; disableMentions?: 'none' | 'all' | 'everyone';
allowedMentions?: MessageMentionOptions; allowedMentions?: MessageMentionOptions;
@ -3020,6 +3021,7 @@ declare module 'discord.js' {
| 'attachments' | 'attachments'
| 'channel' | 'channel'
| 'deletable' | 'deletable'
| 'crosspostable'
| 'editable' | 'editable'
| 'mentions' | 'mentions'
| 'pinnable' | 'pinnable'
@ -3031,6 +3033,7 @@ declare module 'discord.js' {
attachments: Message['attachments']; attachments: Message['attachments'];
channel: Message['channel']; channel: Message['channel'];
readonly deletable: boolean; readonly deletable: boolean;
readonly crosspostable: boolean;
readonly editable: boolean; readonly editable: boolean;
readonly edits: Message['edits']; readonly edits: Message['edits'];
embeds: Message['embeds']; embeds: Message['embeds'];