New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

discord.js

Package Overview
Dependencies
Maintainers
4
Versions
1798
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord.js - npm Package Compare versions

Comparing version 13.0.0-dev.ef92339d073f82cdaa2bc69f7be8443ec16789a7 to 13.0.0-dev.f7e420bf290f5404e8b99b8896c63e178f77bbfc

src/index.mjs

16

package.json
{
"name": "discord.js",
"version": "13.0.0-dev.ef92339d073f82cdaa2bc69f7be8443ec16789a7",
"version": "13.0.0-dev.f7e420bf290f5404e8b99b8896c63e178f77bbfc",
"description": "A powerful library for interacting with the Discord API",
"main": "./src/index.js",
"module": "./src/index.mjs",
"types": "./typings/index.d.ts",
"exports": {
".": [
{
"require": "./src/index.js",
"import": "./esm/discord.mjs"
},
"./src/index.js"
],
"./esm": "./esm/discord.mjs"
"require": "./src/index.js",
"import": "./src/index.mjs"
},

@@ -26,3 +21,3 @@ "scripts": {

"prettier": "prettier --write src/**/*.js typings/**/*.ts",
"prepublishOnly": "npm run test",
"prepublishOnly": "npm run test && gen-esm-wrapper ./src/index.js ./src/index.mjs",
"prepare": "is-ci || husky install",

@@ -74,2 +69,3 @@ "changelog": "conventional-changelog -p angular -i RELEASE_CHANGELOG.md -s"

"eslint-plugin-prettier": "^3.4.0",
"gen-esm-wrapper": "^1.1.1",
"husky": "^6.0.0",

@@ -76,0 +72,0 @@ "is-ci": "^3.0.0",

@@ -8,3 +8,3 @@ <div align="center">

<p>
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=7289da&logo=discord&logoColor=white" alt="Discord server" /></a>
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/v/discord.js.svg?maxAge=3600" alt="NPM version" /></a>

@@ -11,0 +11,0 @@ <a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/dt/discord.js.svg?maxAge=3600" alt="NPM downloads" /></a>

@@ -7,18 +7,29 @@ 'use strict';

module.exports = (client, { d: data }) => {
if (data.type === InteractionTypes.APPLICATION_COMMAND) {
if (!Structures) Structures = require('../../../util/Structures');
const CommandInteraction = Structures.get('CommandInteraction');
let interaction;
switch (data.type) {
case InteractionTypes.APPLICATION_COMMAND: {
if (!Structures) Structures = require('../../../util/Structures');
const CommandInteraction = Structures.get('CommandInteraction');
const interaction = new CommandInteraction(client, data);
interaction = new CommandInteraction(client, data);
break;
}
case InteractionTypes.MESSAGE_COMPONENT: {
if (!Structures) Structures = require('../../../util/Structures');
const MessageComponentInteraction = Structures.get('MessageComponentInteraction');
/**
* Emitted when an interaction is created.
* @event Client#interaction
* @param {Interaction} interaction The interaction which was created
*/
client.emit(Events.INTERACTION_CREATE, interaction);
return;
interaction = new MessageComponentInteraction(client, data);
break;
}
default:
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
return;
}
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
/**
* Emitted when an interaction is created.
* @event Client#interaction
* @param {Interaction} interaction The interaction which was created
*/
client.emit(Events.INTERACTION_CREATE, interaction);
};

@@ -71,3 +71,3 @@ 'use strict';

* An array of queued events before this WebSocketManager became ready
* @type {object[]}
* @type {Object[]}
* @private

@@ -74,0 +74,0 @@ * @name WebSocketManager#packetQueue

@@ -603,3 +603,3 @@ 'use strict';

this.debug(`[IDENTIFY] Shard ${this.id}/${client.options.shardCount}`);
this.debug(`[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${d.intents}`);
this.send({ op: OPCodes.IDENTIFY, d }, true);

@@ -606,0 +606,0 @@ }

@@ -47,2 +47,6 @@ 'use strict';

BUTTON_LABEL: 'MessageButton label must be a string',
BUTTON_URL: 'MessageButton url must be a string',
BUTTON_CUSTOM_ID: 'MessageButton customID must be a string',
FILE_NOT_FOUND: file => `File could not be found: ${file}`,

@@ -49,0 +53,0 @@

@@ -71,2 +71,3 @@ 'use strict';

BaseGuildVoiceChannel: require('./structures/BaseGuildVoiceChannel'),
BaseMessageComponent: require('./structures/BaseMessageComponent'),
CategoryChannel: require('./structures/CategoryChannel'),

@@ -96,4 +97,8 @@ Channel: require('./structures/Channel'),

Message: require('./structures/Message'),
MessageActionRow: require('./structures/MessageActionRow'),
MessageAttachment: require('./structures/MessageAttachment'),
MessageButton: require('./structures/MessageButton'),
MessageCollector: require('./structures/MessageCollector'),
MessageComponentInteraction: require('./structures/MessageComponentInteraction'),
MessageComponentInteractionCollector: require('./structures/MessageComponentInteractionCollector'),
MessageEmbed: require('./structures/MessageEmbed'),

@@ -100,0 +105,0 @@ MessageMentions: require('./structures/MessageMentions'),

@@ -59,3 +59,3 @@ 'use strict';

* Data used for overwriting the permissions for all application commands in a guild.
* @typedef {object} GuildApplicationCommandPermissionData
* @typedef {Object} GuildApplicationCommandPermissionData
* @prop {Snowflake} command The ID of the command

@@ -62,0 +62,0 @@ * @prop {ApplicationCommandPermissionData[]} permissions The permissions for this command

@@ -118,3 +118,3 @@ 'use strict';

if (color) color = resolveColor(color);
if (permissions) permissions = Permissions.resolve(permissions).toString();
if (typeof permissions !== 'undefined') permissions = new Permissions(permissions);

@@ -121,0 +121,0 @@ return this.client.api

@@ -45,4 +45,5 @@ 'use strict';

* @typedef {Object} HTTPAttachmentData
* @property {string|Buffer|Stream} attachment The source of this attachment data
* @property {string} name The file name
* @property {Buffer} file The file buffer
* @property {Buffer|Stream} file The file buffer
*/

@@ -49,0 +50,0 @@

'use strict';
const BaseMessageComponent = require('./BaseMessageComponent');
const MessageAttachment = require('./MessageAttachment');

@@ -154,2 +155,4 @@ const MessageEmbed = require('./MessageEmbed');

const components = this.options.components?.map(c => BaseMessageComponent.create(c).toJSON());
let username;

@@ -200,2 +203,3 @@ let avatarURL;

embeds: isWebhookLike ? embeds : undefined,
components,
username,

@@ -202,0 +206,0 @@ avatar_url: avatarURL,

@@ -135,3 +135,3 @@ 'use strict';

* Data for setting the permissions of an application command.
* @typedef {object} ApplicationCommandPermissionData
* @typedef {Object} ApplicationCommandPermissionData
* @property {Snowflake} id The ID of the role or user

@@ -144,3 +144,3 @@ * @property {ApplicationCommandPermissionType|number} type Whether this permission if for a role or a user

* The object returned when fetching permissions for an application command.
* @typedef {object} ApplicationCommandPermissions
* @typedef {Object} ApplicationCommandPermissions
* @property {Snowflake} id The ID of the role or user

@@ -147,0 +147,0 @@ * @property {ApplicationCommandPermissionType} type Whether this permission if for a role or a user

'use strict';
const APIMessage = require('./APIMessage');
const Interaction = require('./Interaction');
const InteractionResponses = require('./interfaces/InteractionResponses');
const WebhookClient = require('../client/WebhookClient');
const { Error } = require('../errors');
const Collection = require('../util/Collection');
const { ApplicationCommandOptionTypes, InteractionResponseTypes } = require('../util/Constants');
const MessageFlags = require('../util/MessageFlags');
const { ApplicationCommandOptionTypes } = require('../util/Constants');

@@ -14,2 +12,3 @@ /**

* @extends {Interaction}
* @implements {InteractionResponses}
*/

@@ -74,122 +73,2 @@ class CommandInteraction extends Interaction {

/**
* Options for deferring the reply to a {@link CommandInteraction}.
* @typedef {Object} InteractionDeferOptions
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
*/
/**
* Defers the reply to this interaction.
* @param {InteractionDeferOptions} [options] Options for deferring the reply to this interaction
* @returns {Promise<void>}
* @example
* // Defer the reply to this interaction
* interaction.defer()
* .then(console.log)
* .catch(console.error)
* @example
* // Defer to send an ephemeral reply later
* interaction.defer({ ephemeral: true })
* .then(console.log)
* .catch(console.error);
*/
async defer({ ephemeral } = {}) {
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
await this.client.api.interactions(this.id, this.token).callback.post({
data: {
type: InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
data: {
flags: ephemeral ? MessageFlags.FLAGS.EPHEMERAL : undefined,
},
},
});
this.deferred = true;
}
/**
* Options for a reply to an interaction.
* @typedef {BaseMessageOptions} InteractionReplyOptions
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
* @property {MessageEmbed[]|Object[]} [embeds] An array of embeds for the message
*/
/**
* Creates a reply to this interaction.
* @param {string|APIMessage|MessageAdditions} content The content for the reply
* @param {InteractionReplyOptions} [options] Additional options for the reply
* @returns {Promise<void>}
* @example
* // Reply to the interaction with an embed
* const embed = new MessageEmbed().setDescription('Pong!');
*
* interaction.reply(embed)
* .then(console.log)
* .catch(console.error);
* @example
* // Create an ephemeral reply
* interaction.reply('Pong!', { ephemeral: true })
* .then(console.log)
* .catch(console.error);
*/
async reply(content, options) {
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options);
const { data, files } = await apiMessage.resolveData().resolveFiles();
await this.client.api.interactions(this.id, this.token).callback.post({
data: {
type: InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE,
data,
},
files,
});
this.replied = true;
}
/**
* Fetches the initial reply to this interaction.
* @see Webhook#fetchMessage
* @returns {Promise<Message|Object>}
* @example
* // Fetch the reply to this interaction
* interaction.fetchReply()
* .then(reply => console.log(`Replied with ${reply.content}`))
* .catch(console.error);
*/
async fetchReply() {
const raw = await this.webhook.fetchMessage('@original');
return this.channel?.messages.add(raw) ?? raw;
}
/**
* Edits the initial reply to this interaction.
* @see Webhook#editMessage
* @param {string|APIMessage|MessageAdditions} content The new content for the message
* @param {WebhookEditMessageOptions} [options] The options to provide
* @returns {Promise<Message|Object>}
* @example
* // Edit the reply to this interaction
* interaction.editReply('New content')
* .then(console.log)
* .catch(console.error);
*/
async editReply(content, options) {
const raw = await this.webhook.editMessage('@original', content, options);
return this.channel?.messages.add(raw) ?? raw;
}
/**
* Deletes the initial reply to this interaction.
* @see Webhook#deleteMessage
* @returns {Promise<void>}
* @example
* // Delete the reply to this interaction
* interaction.deleteReply()
* .then(console.log)
* .catch(console.error);
*/
async deleteReply() {
await this.webhook.deleteMessage('@original');
}
/**
* Represents an option of a received command interaction.

@@ -209,20 +88,2 @@ * @typedef {Object} CommandInteractionOption

/**
* Send a follow-up message to this interaction.
* @param {string|APIMessage|MessageAdditions} content The content for the reply
* @param {InteractionReplyOptions} [options] Additional options for the reply
* @returns {Promise<Message|Object>}
*/
async followUp(content, options) {
const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options);
const { data, files } = await apiMessage.resolveData().resolveFiles();
const raw = await this.client.api.webhooks(this.applicationID, this.token).post({
data,
files,
});
return this.channel?.messages.add(raw) ?? raw;
}
/**
* Transforms an option received from the API.

@@ -273,4 +134,15 @@ * @param {Object} option The received option

}
// These are here only for documentation purposes - they are implemented by InteractionResponses
/* eslint-disable no-empty-function */
defer() {}
reply() {}
fetchReply() {}
editReply() {}
deleteReply() {}
followUp() {}
}
InteractionResponses.applyToClass(CommandInteraction, ['deferUpdate', 'update']);
module.exports = CommandInteraction;

@@ -94,2 +94,4 @@ 'use strict';

awaitMessages() {}
createMessageComponentInteractionCollector() {}
awaitMessageComponentInteractions() {}
// Doesn't work on DM channels; bulkDelete() {}

@@ -96,0 +98,0 @@ }

@@ -179,2 +179,4 @@ 'use strict';

* * MEMBER_VERIFICATION_GATE_ENABLED
* * MONETIZATION_ENABLED
* * MORE_STICKERS
* * NEWS

@@ -184,2 +186,3 @@ * * PARTNERED

* * RELAY_ENABLED
* * TICKETED_EVENTS_ENABLED
* * VANITY_URL

@@ -186,0 +189,0 @@ * * VERIFIED

@@ -115,4 +115,12 @@ 'use strict';

}
/**
* Indicates whether this interaction is a component interaction.
* @returns {boolean}
*/
isMessageComponent() {
return InteractionTypes[this.type] === InteractionTypes.MESSAGE_COMPONENT;
}
}
module.exports = Interaction;

@@ -9,2 +9,3 @@ 'use strict';

const { RangeError, TypeError } = require('../../errors');
const MessageComponentInteractionCollector = require('../MessageComponentInteractionCollector');

@@ -320,2 +321,41 @@ /**

/**
* Creates a button interaction collector.
* @param {CollectorFilter} filter The filter to apply
* @param {MessageComponentInteractionCollectorOptions} [options={}] Options to send to the collector
* @returns {MessageComponentInteractionCollector}
* @example
* // Create a button interaction collector
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* const collector = channel.createMessageComponentInteractionCollector(filter, { time: 15000 });
* collector.on('collect', i => console.log(`Collected ${i.customID}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/
createMessageComponentInteractionCollector(filter, options = {}) {
return new MessageComponentInteractionCollector(this, filter, options);
}
/**
* Similar to createMessageComponentInteractionCollector but in promise form.
* Resolves with a collection of interactions that pass the specified filter.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitMessageComponentInteractionsOptions} [options={}] Optional options to pass to the internal collector
* @returns {Promise<Collection<string, MessageComponentInteraction>>}
* @example
* // Create a button interaction collector
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* channel.awaitMessageComponentInteractions(filter, { time: 15000 })
* .then(collected => console.log(`Collected ${collected.size} interactions`))
* .catch(console.error);
*/
awaitMessageComponentInteractions(filter, options = {}) {
return new Promise((resolve, reject) => {
const collector = this.createMessageComponentInteractionCollector(filter, options);
collector.once('end', (interactions, reason) => {
if (options.errors && options.errors.includes(reason)) reject(interactions);
else resolve(interactions);
});
});
}
/**
* Bulk deletes given messages that are newer than two weeks.

@@ -384,2 +424,4 @@ * @param {Collection<Snowflake, Message>|MessageResolvable[]|number} messages

'awaitMessages',
'createMessageComponentInteractionCollector',
'awaitMessageComponentInteractions',
);

@@ -386,0 +428,0 @@ }

@@ -5,4 +5,6 @@ 'use strict';

const Base = require('./Base');
const BaseMessageComponent = require('./BaseMessageComponent');
const ClientApplication = require('./ClientApplication');
const MessageAttachment = require('./MessageAttachment');
const MessageComponentInteractionCollector = require('./MessageComponentInteractionCollector');
const Embed = require('./MessageEmbed');

@@ -128,2 +130,8 @@ const Mentions = require('./MessageMentions');

/**
* A list of MessageActionRows in the message
* @type {MessageActionRow[]}
*/
this.components = (data.components ?? []).map(c => BaseMessageComponent.create(c, this.client));
/**
* A collection of attachments in the message - e.g. Pictures - mapped by their ID

@@ -240,3 +248,3 @@ * @type {Collection<Snowflake, MessageAttachment>}

* Partial data of the interaction that a message is a reply to
* @typedef {object} MessageInteraction
* @typedef {Object} MessageInteraction
* @property {Snowflake} id The ID of the interaction

@@ -288,2 +296,4 @@ * @property {InteractionType} type The type of the interaction

else this.embeds = this.embeds.slice();
if ('components' in data) this.components = data.components.map(c => BaseMessageComponent.create(c, this.client));
else this.components = this.components.slice();

@@ -415,2 +425,47 @@ if ('attachments' in data) {

/**
* Creates a message component interaction collector.
* @param {CollectorFilter} filter The filter to apply
* @param {MessageComponentInteractionCollectorOptions} [options={}] Options to send to the collector
* @returns {MessageComponentInteractionCollector}
* @example
* // Create a message component interaction collector
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* const collector = message.createMessageComponentInteractionCollector(filter, { time: 15000 });
* collector.on('collect', i => console.log(`Collected ${i.customID}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/
createMessageComponentInteractionCollector(filter, options = {}) {
return new MessageComponentInteractionCollector(this, filter, options);
}
/**
* An object containing the same properties as CollectorOptions, but a few more:
* @typedef {MessageComponentInteractionCollectorOptions} AwaitMessageComponentInteractionsOptions
* @property {string[]} [errors] Stop/end reasons that cause the promise to reject
*/
/**
* Similar to createMessageComponentInteractionCollector but in promise form.
* Resolves with a collection of interactions that pass the specified filter.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitMessageComponentInteractionsOptions} [options={}] Optional options to pass to the internal collector
* @returns {Promise<Collection<string, MessageComponentInteraction>>}
* @example
* // Create a message component interaction collector
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* message.awaitMessageComponentInteractions(filter, { time: 15000 })
* .then(collected => console.log(`Collected ${collected.size} interactions`))
* .catch(console.error);
*/
awaitMessageComponentInteractions(filter, options = {}) {
return new Promise((resolve, reject) => {
const collector = this.createMessageComponentInteractionCollector(filter, options);
collector.once('end', (interactions, reason) => {
if (options.errors && options.errors.includes(reason)) reject(interactions);
else resolve(interactions);
});
});
}
/**
* Whether the message is editable by the client user

@@ -482,3 +537,3 @@ * @type {boolean}

* @typedef {Object} MessageEditOptions
* @property {string} [content] Content to be edited
* @property {?string} [content] Content to be edited
* @property {MessageEmbed|Object} [embed] An embed to be added/edited

@@ -495,4 +550,4 @@ * @property {string|boolean} [code] Language for optional codeblock formatting to apply

* Edits the content of the message.
* @param {string|APIMessage} [content] The new content for the message
* @param {MessageEditOptions|MessageEmbed} [options] The options to provide
* @param {?(string|APIMessage)} [content] The new content for the message
* @param {MessageEditOptions|MessageEmbed|MessageAttachment|MessageAttachment[]} [options] The options to provide
* @returns {Promise<Message>}

@@ -499,0 +554,0 @@ * @example

'use strict';
const { RangeError } = require('../errors');
const Util = require('../util/Util');

@@ -4,0 +5,0 @@

@@ -160,2 +160,4 @@ 'use strict';

awaitMessages() {}
createMessageComponentInteractionCollector() {}
awaitMessageComponentInteractions() {}
bulkDelete() {}

@@ -162,0 +164,0 @@ }

@@ -802,5 +802,6 @@ 'use strict';

* * APPLICATION_COMMAND
* * MESSAGE_COMPONENT
* @typedef {string} InteractionType
*/
exports.InteractionTypes = createEnum([null, 'PING', 'APPLICATION_COMMAND']);
exports.InteractionTypes = createEnum([null, 'PING', 'APPLICATION_COMMAND', 'MESSAGE_COMPONENT']);

@@ -812,2 +813,4 @@ /**

* * DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
* * DEFERRED_MESSAGE_UPDATE
* * UPDATE_MESSAGE
* @typedef {string} InteractionResponseType

@@ -822,5 +825,26 @@ */

'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE',
'DEFERRED_MESSAGE_UPDATE',
'UPDATE_MESSAGE',
]);
/**
* The type of a message component
* ACTION_ROW
* BUTTON
* @typedef {string} MessageComponentType
*/
exports.MessageComponentTypes = createEnum([null, 'ACTION_ROW', 'BUTTON']);
/**
* The style of a message button
* PRIMARY
* SECONDARY
* SUCCESS
* DANGER
* LINK
* @typedef {string} MessageButtonStyle
*/
exports.MessageButtonStyles = createEnum([null, 'PRIMARY', 'SECONDARY', 'SUCCESS', 'DANGER', 'LINK']);
/**
* NSFW level of a Guild

@@ -827,0 +851,0 @@ * * DEFAULT

@@ -23,2 +23,3 @@ 'use strict';

* * **`CommandInteraction`**
* * **`MessageComponentInteraction`**
* @typedef {string} ExtendableStructure

@@ -115,4 +116,5 @@ */

CommandInteraction: require('../structures/CommandInteraction'),
MessageComponentInteraction: require('../structures/MessageComponentInteraction'),
};
module.exports = Structures;

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc