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
2
Versions
1788
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 11.4.2 to 11.5.0

src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js

46

package.json
{
"name": "discord.js",
"version": "11.4.2",
"version": "11.5.0",
"description": "A powerful library for interacting with the Discord API",

@@ -13,2 +13,3 @@ "main": "./src/index",

"lint:fix": "eslint --fix src",
"lint:typings": "tslint typings/index.d.ts typings/discord.js-test.ts",
"webpack": "parallel-webpack"

@@ -40,20 +41,46 @@ },

"tweetnacl": "^1.0.0",
"ws": "^4.0.0"
"ws": "^6.0.0"
},
"peerDependencies": {
"bufferutil": "^3.0.3",
"bufferutil": "^4.0.0",
"erlpack": "discordapp/erlpack",
"libsodium-wrappers": "^0.7.3",
"node-opus": "^0.2.7",
"opusscript": "^0.0.6",
"sodium": "^2.0.3",
"libsodium-wrappers": "^0.7.3",
"uws": "^9.14.0"
"@discordjs/uws": "^10.149.0"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"erlpack": {
"optional": true
},
"node-opus": {
"optional": true
},
"opusscript": {
"optional": true
},
"sodium": {
"optional": true
},
"libsodium-wrappers": {
"optional": true
},
"uws": {
"optional": true
}
},
"devDependencies": {
"@types/node": "^9.4.6",
"discord.js-docgen": "discordjs/docgen",
"eslint": "^4.18.0",
"parallel-webpack": "^2.2.0",
"uglifyjs-webpack-plugin": "^1.2.0",
"webpack": "^3.11.0"
"eslint": "^5.4.0",
"parallel-webpack": "^2.3.0",
"tslint": "^3.15.1",
"tslint-config-typings": "^0.2.4",
"typescript": "^3.0.1",
"uglifyjs-webpack-plugin": "^1.3.0",
"webpack": "^4.17.0"
},

@@ -66,2 +93,3 @@ "engines": {

"uws": false,
"@discordjs/uws": false,
"erlpack": false,

@@ -68,0 +96,0 @@ "prism-media": false,

2

README.md

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

- [libsodium.js](https://www.npmjs.com/package/libsodium-wrappers) (`npm install libsodium-wrappers`)
- [uws](https://www.npmjs.com/package/uws) for a much faster WebSocket connection (`npm install uws`)
- [uws](https://www.npmjs.com/package/@discordjs/uws) for a much faster WebSocket connection (`npm install @discordjs/uws`)

@@ -50,0 +50,0 @@ ## Example usage

const Action = require('./Action');
const TextChannel = require('../../structures/TextChannel');
const VoiceChannel = require('../../structures/VoiceChannel');
const CategoryChannel = require('../../structures/CategoryChannel');
const NewsChannel = require('../../structures/NewsChannel');
const StoreChannel = require('../../structures/StoreChannel');
const Constants = require('../../util/Constants');
const ChannelTypes = Constants.ChannelTypes;
const Util = require('../../util/Util');

@@ -9,6 +15,40 @@

const channel = client.channels.get(data.id);
let channel = client.channels.get(data.id);
if (channel) {
const oldChannel = Util.cloneObject(channel);
channel.setup(data);
// If the channel is changing types, we need to follow a different process
if (ChannelTypes[channel.type.toUpperCase()] !== data.type) {
// Determine which channel class we're changing to
let channelClass;
switch (data.type) {
case ChannelTypes.TEXT:
channelClass = TextChannel;
break;
case ChannelTypes.VOICE:
channelClass = VoiceChannel;
break;
case ChannelTypes.CATEGORY:
channelClass = CategoryChannel;
break;
case ChannelTypes.NEWS:
channelClass = NewsChannel;
break;
case ChannelTypes.STORE:
channelClass = StoreChannel;
break;
}
// Create the new channel instance and copy over cached data
const newChannel = new channelClass(channel.guild, data);
if (channel.messages && newChannel.messages) {
for (const [id, message] of channel.messages) newChannel.messages.set(id, message);
}
channel = newChannel;
this.client.channels.set(channel.id, channel);
} else {
channel.setup(data);
}
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);

@@ -15,0 +55,0 @@ return {

@@ -19,3 +19,2 @@ const Action = require('./Action');

channel.lastMessageID = lastMessage.id;
channel.lastMessage = lastMessage;
if (user) {

@@ -35,3 +34,2 @@ user.lastMessageID = lastMessage.id;

channel.lastMessageID = data.id;
channel.lastMessage = message;
if (user) {

@@ -38,0 +36,0 @@ user.lastMessageID = data.id;

@@ -189,7 +189,7 @@ const EventEmitter = require('events');

* Current status of the client's connection to Discord
* @type {?number}
* @type {Status}
* @readonly
*/
get status() {
return this.ws.connection.status;
return this.ws.connection ? this.ws.connection.status : Constants.Status.IDLE;
}

@@ -327,3 +327,3 @@

* client.fetchInvite('https://discord.gg/bRCvFy9')
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`)
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
* .catch(console.error);

@@ -400,4 +400,5 @@ */

* @returns {Promise<OAuth2Application>}
* @example
* client.fetchApplication()
* .then(application => console.log(`Obtained application with name: ${application.name}`)
* .then(application => console.log(`Obtained application with name: ${application.name}`))
* .catch(console.error);

@@ -515,3 +516,3 @@ */

*/
_validateOptions(options = this.options) {
_validateOptions(options = this.options) { // eslint-disable-line complexity
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount)) {

@@ -547,2 +548,5 @@ throw new TypeError('The shardCount option must be a number.');

if (!(options.disabledEvents instanceof Array)) throw new TypeError('The disabledEvents option must be an Array.');
if (typeof options.retryLimit !== 'number' || isNaN(options.retryLimit)) {
throw new TypeError('The retryLimit options must be a number.');
}
}

@@ -549,0 +553,0 @@ }

@@ -5,8 +5,10 @@ const Constants = require('../util/Constants');

const User = require('../structures/User');
const CategoryChannel = require('../structures/CategoryChannel');
const DMChannel = require('../structures/DMChannel');
const Emoji = require('../structures/Emoji');
const GuildChannel = require('../structures/GuildChannel');
const TextChannel = require('../structures/TextChannel');
const VoiceChannel = require('../structures/VoiceChannel');
const GuildChannel = require('../structures/GuildChannel');
const CategoryChannel = require('../structures/CategoryChannel');
const NewsChannel = require('../structures/NewsChannel');
const StoreChannel = require('../structures/StoreChannel');
const DMChannel = require('../structures/DMChannel');
const GroupDMChannel = require('../structures/GroupDMChannel');

@@ -62,12 +64,21 @@

} else if (guild) {
if (data.type === Constants.ChannelTypes.TEXT) {
channel = new TextChannel(guild, data);
guild.channels.set(channel.id, channel);
} else if (data.type === Constants.ChannelTypes.VOICE) {
channel = new VoiceChannel(guild, data);
guild.channels.set(channel.id, channel);
} else if (data.type === Constants.ChannelTypes.CATEGORY) {
channel = new CategoryChannel(guild, data);
guild.channels.set(channel.id, channel);
switch (data.type) {
case Constants.ChannelTypes.TEXT:
channel = new TextChannel(guild, data);
break;
case Constants.ChannelTypes.VOICE:
channel = new VoiceChannel(guild, data);
break;
case Constants.ChannelTypes.CATEGORY:
channel = new CategoryChannel(guild, data);
break;
case Constants.ChannelTypes.NEWS:
channel = new NewsChannel(guild, data);
break;
case Constants.ChannelTypes.STORE:
channel = new StoreChannel(guild, data);
break;
}
guild.channels.set(channel.id, channel);
}

@@ -74,0 +85,0 @@ }

@@ -310,2 +310,3 @@ const path = require('path');

* 'DEFAULT',
* 'WHITE',
* 'AQUA',

@@ -312,0 +313,0 @@ * 'GREEN',

@@ -45,7 +45,13 @@ const RequestHandler = require('./RequestHandler');

} else if (err.status >= 500 && err.status < 600) {
this.queue.unshift(item);
this.resetTimeout = this.client.setTimeout(() => {
if (item.retries === this.client.options.retryLimit) {
item.reject(err);
this.handle();
this.resetTimeout = null;
}, 1e3 + this.client.options.restTimeOffset);
} else {
item.retries++;
this.queue.unshift(item);
this.resetTimeout = this.client.setTimeout(() => {
this.handle();
this.resetTimeout = null;
}, 1e3 + this.client.options.restTimeOffset);
}
} else {

@@ -52,0 +58,0 @@ item.reject(err.status >= 400 && err.status < 500 ?

@@ -69,10 +69,16 @@ const RequestHandler = require('./RequestHandler');

this.queue.unshift(item);
this.restManager.client.setTimeout(() => {
this.client.setTimeout(() => {
this.globalLimit = false;
resolve();
}, Number(res.headers['retry-after']) + this.restManager.client.options.restTimeOffset);
}, Number(res.headers['retry-after']) + this.client.options.restTimeOffset);
if (res.headers['x-ratelimit-global']) this.globalLimit = true;
} else if (err.status >= 500 && err.status < 600) {
this.queue.unshift(item);
this.restManager.client.setTimeout(resolve, 1e3 + this.restManager.client.options.restTimeOffset);
if (item.retries === this.client.options.retryLimit) {
item.reject(err);
resolve();
} else {
item.retries++;
this.queue.unshift(item);
this.client.setTimeout(resolve, 1e3 + this.client.options.restTimeOffset);
}
} else {

@@ -93,6 +99,6 @@ item.reject(err.status >= 400 && err.status < 500 ?

* @param {Object} rateLimitInfo Object containing the rate limit info
* @param {number} rateLimitInfo.requestLimit Number of requests that can be made to this endpoint
* @param {number} rateLimitInfo.limit Number of requests that can be made to this endpoint
* @param {number} rateLimitInfo.timeDifference Delta-T in ms between your system and Discord servers
* @param {string} rateLimitInfo.path Path used for request that triggered this event
* @param {string} rateLimitInfo.method HTTP method used for request that triggered this event
* @param {string} rateLimitInfo.path Path used for request that triggered this event
*/

@@ -106,5 +112,5 @@ this.client.emit(RATE_LIMIT, {

}
this.restManager.client.setTimeout(
this.client.setTimeout(
() => resolve(data),
this.requestResetTime - Date.now() + this.timeDifference + this.restManager.client.options.restTimeOffset
this.requestResetTime - Date.now() + this.timeDifference + this.client.options.restTimeOffset
);

@@ -111,0 +117,0 @@ } else {

@@ -31,2 +31,3 @@ const UserAgentManager = require('./UserAgentManager');

reject,
retries: 0,
});

@@ -33,0 +34,0 @@ });

@@ -62,2 +62,9 @@ const querystring = require('querystring');

fetchEmbed(guildID) {
return this.rest.makeRequest('get', Endpoints.Guild(guildID).embed, true).then(data => ({
enabled: data.enabled,
channel: data.channel_id ? this.client.channels.get(data.channel_id) : null,
}));
}
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split, code, reply } = {}, files = null) {

@@ -257,8 +264,29 @@ return new Promise((resolve, reject) => { // eslint-disable-line complexity

createChannel(guild, channelName, channelType, overwrites, reason) {
createChannel(guild, name, options) {
const {
type,
topic,
nsfw,
bitrate,
userLimit,
parent,
permissionOverwrites,
position,
rateLimitPerUser,
reason,
} = options;
return this.rest.makeRequest('post', Endpoints.Guild(guild).channels, true, {
name: channelName,
type: channelType ? Constants.ChannelTypes[channelType.toUpperCase()] : 'text',
permission_overwrites: resolvePermissions.call(this, overwrites, guild),
}, undefined, reason).then(data => this.client.actions.ChannelCreate.handle(data).channel);
name,
topic,
type: type ? Constants.ChannelTypes[type.toUpperCase()] : 'text',
nsfw,
bitrate,
user_limit: userLimit,
parent_id: parent instanceof Channel ? parent.id : parent,
permission_overwrites: resolvePermissions.call(this, permissionOverwrites, guild),
position,
rate_limit_per_user: rateLimitPerUser,
},
undefined,
reason).then(data => this.client.actions.ChannelCreate.handle(data).channel);
}

@@ -326,5 +354,7 @@

data.user_limit = typeof _data.userLimit !== 'undefined' ? _data.userLimit : channel.userLimit;
data.parent_id = _data.parent;
data.parent_id = _data.parent instanceof Channel ? _data.parent.id : _data.parent;
data.permission_overwrites = _data.permissionOverwrites ?
resolvePermissions.call(this, _data.permissionOverwrites, channel.guild) : undefined;
data.rate_limit_per_user = typeof _data.rateLimitPerUser !== 'undefined' ?
_data.rateLimitPerUser : channel.rateLimitPerUser;
return this.rest.makeRequest('patch', Endpoints.Channel(channel), true, data, undefined, reason).then(newData =>

@@ -463,3 +493,3 @@ this.client.actions.ChannelUpdate.handle(newData).updated

putGuildMember(guild, user, options) {
putGuildMember(guild, userID, options) {
options.access_token = options.accessToken;

@@ -472,3 +502,3 @@ if (options.roles) {

}
return this.rest.makeRequest('put', Endpoints.Guild(guild).Member(user.id), true, options)
return this.rest.makeRequest('put', Endpoints.Guild(guild).Member(userID), true, options)
.then(data => this.client.actions.GuildMemberGet.handle(guild, data).member);

@@ -486,5 +516,11 @@ }

if (data.channel) {
data.channel_id = this.client.resolver.resolveChannel(data.channel).id;
data.channel = null;
const channel = this.client.resolver.resolveChannel(data.channel);
if (!channel || channel.guild.id !== member.guild.id || channel.type !== 'voice') {
return Promise.reject(new Error('Could not resolve channel to a guild voice channel.'));
}
data.channel_id = channel.id;
} else if (data.channel === null) {
data.channel_id = null;
}
data.channel = undefined;
if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role);

@@ -606,2 +642,10 @@

getGuildBan(guild, user) {
const id = this.client.resolver.resolveUserID(user);
return this.rest.makeRequest('get', `${Endpoints.Guild(guild).bans}/${id}`, true).then(ban => ({
reason: ban.reason,
user: this.client.dataManager.newUser(ban.user),
}));
}
getGuildBans(guild) {

@@ -685,2 +729,7 @@ return this.rest.makeRequest('get', Endpoints.Guild(guild).bans, true).then(bans =>

getGuildVanityCode(guild) {
return this.rest.makeRequest('get', Endpoints.Guild(guild).vanityURL, true)
.then(res => res.code);
}
pruneGuildMembers(guild, days, dry, reason) {

@@ -864,2 +913,9 @@ return this.rest.makeRequest(dry ?

updateEmbed(guildID, embed, reason) {
return this.rest.makeRequest('patch', Endpoints.Guild(guildID).embed, true, {
enabled: embed.enabled,
channel_id: this.client.resolver.resolveChannelID(embed.channel),
}, undefined, reason);
}
setRolePositions(guildID, roles) {

@@ -866,0 +922,0 @@ return this.rest.makeRequest('patch', Endpoints.Guild(guildID).roles, true, roles).then(() =>

@@ -8,5 +8,5 @@ const EventEmitter = require('events');

class VolumeInterface extends EventEmitter {
constructor({ volume = 0 } = {}) {
constructor({ volume = 1 } = {}) {
super();
this.setVolume(volume || 1);
this.setVolume(volume);
}

@@ -13,0 +13,0 @@

@@ -7,3 +7,3 @@ const Constants = require('../../util/Constants');

try {
WebSocket = require('uws');
WebSocket = require('@discordjs/uws');
} catch (err) {

@@ -10,0 +10,0 @@ WebSocket = require('ws');

@@ -19,3 +19,8 @@ const AbstractHandler = require('./AbstractHandler');

const time = new Date(data.last_pin_timestamp);
if (channel && time) client.emit(Constants.Events.CHANNEL_PINS_UPDATE, channel, time);
if (channel && time) {
// Discord sends null for last_pin_timestamp if the last pinned message was removed
channel.lastPinTimestamp = time.getTime() || null;
client.emit(Constants.Events.CHANNEL_PINS_UPDATE, channel, time);
}
}

@@ -27,7 +32,8 @@ }

* can be provided easily here - you need to manually check the pins yourself.
* <warn>The `time` parameter will be a Unix Epoch Date object when there are no pins left.</warn>
* @event Client#channelPinsUpdate
* @param {Channel} channel The channel that the pins update occured in
* @param {Date} time The time of the pins update
* @param {Date} time The time when the last pinned message was pinned
*/
module.exports = ChannelPinsUpdate;

@@ -34,2 +34,3 @@ const Constants = require('../../../util/Constants');

this.register(Constants.WSEvents.GUILD_MEMBERS_CHUNK, require('./handlers/GuildMembersChunk'));
this.register(Constants.WSEvents.GUILD_INTEGRATIONS_UPDATE, require('./handlers/GuildIntegrationsUpdate'));
this.register(Constants.WSEvents.CHANNEL_CREATE, require('./handlers/ChannelCreate'));

@@ -57,2 +58,3 @@ this.register(Constants.WSEvents.CHANNEL_DELETE, require('./handlers/ChannelDelete'));

this.register(Constants.WSEvents.MESSAGE_REACTION_REMOVE_ALL, require('./handlers/MessageReactionRemoveAll'));
this.register(Constants.WSEvents.WEBHOOKS_UPDATE, require('./handlers/WebhooksUpdate'));
}

@@ -59,0 +61,0 @@

@@ -19,3 +19,3 @@ const browser = typeof window !== 'undefined';

try {
return require('uws');
return require('@discordjs/uws');
} catch (e) {

@@ -63,3 +63,3 @@ return require('ws');

* The current status of the client
* @type {number}
* @type {Status}
*/

@@ -217,3 +217,3 @@ this.status = Constants.Status.IDLE;

if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
this.debug(`Tried to send packet ${data} but no WebSocket is available!`);
this.debug(`Tried to send packet ${JSON.stringify(data)} but no WebSocket is available!`);
return;

@@ -231,3 +231,3 @@ }

if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
this.debug(`Tried to send packet ${data} but no WebSocket is available!`);
this.debug(`Tried to send packet ${JSON.stringify(data)} but no WebSocket is available!`);
return;

@@ -234,0 +234,0 @@ }

@@ -50,2 +50,3 @@ const Util = require('./util/Util');

MessageReaction: require('./structures/MessageReaction'),
NewsChannel: require('./structures/NewsChannel'),
OAuth2Application: require('./structures/OAuth2Application'),

@@ -61,2 +62,3 @@ ClientOAuth2Application: require('./structures/OAuth2Application'),

Role: require('./structures/Role'),
StoreChannel: require('./structures/StoreChannel'),
TextChannel: require('./structures/TextChannel'),

@@ -63,0 +65,0 @@ User: require('./structures/User'),

@@ -23,2 +23,4 @@ const Snowflake = require('../util/Snowflake');

* * `category` - a guild category channel
* * `news` - a guild news channel
* * `store` - a guild store channel
* @type {string}

@@ -25,0 +27,0 @@ */

@@ -32,2 +32,8 @@ const Channel = require('./Channel');

this.lastMessageID = data.last_message_id;
/**
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
}

@@ -46,2 +52,3 @@

/* eslint-disable no-empty-function */
get lastPinAt() {}
send() {}

@@ -48,0 +55,0 @@ sendMessage() {}

@@ -87,3 +87,3 @@ const Constants = require('../util/Constants');

/**
* Whether the moej is deletable by the client user
* Whether the emoji is deletable by the client user
* @type {boolean}

@@ -166,2 +166,7 @@ * @readonly

if (this.managed) return Promise.reject(new Error('Emoji is managed and has no Author.'));
if (!this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS)) {
return Promise.reject(
new Error(`Client must have Manage Emoji permission in guild ${this.guild} to see emoji authors.`)
);
}
return this.client.rest.makeRequest('get', Constants.Endpoints.Guild(this.guild).Emoji(this.id), true)

@@ -168,0 +173,0 @@ .then(emoji => this.client.dataManager.newUser(emoji.user));

@@ -102,2 +102,8 @@ const Channel = require('./Channel');

this.lastMessageID = data.last_message_id;
/**
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
}

@@ -216,2 +222,3 @@

/* eslint-disable no-empty-function */
get lastPinAt() {}
send() {}

@@ -218,0 +225,0 @@ sendMessage() {}

@@ -109,3 +109,3 @@ const util = require('util');

/**
* The full amount of members in this guild as of `READY`
* The full amount of members in this guild
* @type {number}

@@ -229,3 +229,4 @@ */

const member = this.members.get(voiceState.user_id);
if (member) {
const voiceChannel = this.channels.get(voiceState.channel_id);
if (member && voiceChannel) {
member.serverMute = voiceState.mute;

@@ -237,3 +238,3 @@ member.serverDeaf = voiceState.deaf;

member.voiceChannelID = voiceState.channel_id;
this.channels.get(voiceState.channel_id).members.set(member.user.id, member);
voiceChannel.members.set(member.user.id, member);
}

@@ -474,4 +475,26 @@ }

/**
* An object containing information about a guild member's ban.
* @typedef {Object} BanInfo
* @property {User} user User that was banned
* @property {?string} reason Reason the user was banned
*/
/**
* Fetch a ban for a user.
* @returns {Promise<BanInfo>}
* @param {UserResolvable} user The user to fetch the ban for
* @example
* // Get ban
* guild.fetchBan(message.author)
* .then(({ user, reason }) => console.log(`${user.tag} was banned for the reason: ${reason}.`))
* .catch(console.error);
*/
fetchBan(user) {
return this.client.rest.methods.getGuildBan(this, user);
}
/**
* Fetch a collection of banned users in this guild.
* @returns {Promise<Collection<Snowflake, User>>}
* @returns {Promise<Collection<Snowflake, User|BanInfo>>}
* @param {boolean} [withReasons=false] Whether or not to include the ban reason(s)
* @example

@@ -483,3 +506,4 @@ * // Fetch bans in guild

*/
fetchBans() {
fetchBans(withReasons = false) {
if (withReasons) return this.client.rest.methods.getGuildBans(this);
return this.client.rest.methods.getGuildBans(this)

@@ -513,2 +537,22 @@ .then(bans => {

/**
* Fetches the vanity url invite code to this guild.
* Resolves with a string matching the vanity url invite code, not the full url.
* @returns {Promise<string>}
* @example
* // Fetch invites
* guild.fetchVanityCode()
* .then(code => {
* console.log(`Vanity URL: https://discord.gg/${code}`);
* })
* .catch(console.error);
*/
fetchVanityCode() {
if (!this.features.includes('VANITY_URL')) {
return Promise.reject(new Error('This guild does not have the VANITY_URL feature enabled.'));
}
return this.client.rest.methods.getGuildVanityCode(this);
}
/**
* Fetch all webhooks for the guild.

@@ -540,2 +584,22 @@ * @returns {Promise<Collection<Snowflake, Webhook>>}

/**
* The Guild Embed object
* @typedef {Object} GuildEmbedData
* @property {boolean} enabled Whether the embed is enabled
* @property {?ChannelResolvable} channel The embed channel
*/
/**
* Fetches the guild embed.
* @returns {Promise<GuildEmbedData>}
* @example
* // Fetches the guild embed
* guild.fetchEmbed()
* .then(embed => console.log(`The embed is ${embed.enabled ? 'enabled' : 'disabled'}`))
* .catch(console.error);
*/
fetchEmbed() {
return this.client.rest.methods.fetchEmbed(this.id);
}
/**
* Fetch audit logs for this guild.

@@ -547,3 +611,3 @@ * @param {Object} [options={}] Options for fetching audit logs

* @param {UserResolvable} [options.user] Only show entries involving this user
* @param {string|number} [options.type] Only show entries involving this action type
* @param {AuditLogAction} [options.type] Only show entries involving this action type
* @returns {Promise<GuildAuditLogs>}

@@ -574,3 +638,4 @@ * @example

addMember(user, options) {
if (this.members.has(user.id)) return Promise.resolve(this.members.get(user.id));
user = this.client.resolver.resolveUserID(user);
if (this.members.has(user)) return Promise.resolve(this.members.get(user));
return this.client.rest.methods.putGuildMember(this, user, options);

@@ -982,7 +1047,7 @@ }

* @property {PermissionResolvable} [allow] The permissions to allow
* @property {PermissionResolvable} [allowed] The permissions to allow
* **(deprecated)**
* @property {PermissionResolvable} [allowed] The permissions to allow
* @property {PermissionResolvable} [deny] The permissions to deny
* @property {PermissionResolvable} [denied] The permissions to deny
* **(deprecated)**
* @property {PermissionResolvable} [denied] The permissions to deny
* @property {GuildMemberResolvable|RoleResolvable} memberOrRole Member or role this overwrite is for

@@ -994,9 +1059,12 @@ */

* @param {string} name The name of the new channel
* @param {string} [type='text'] The type of the new channel, either `text` or `voice` or `category`
* @param {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [overwrites] Permission overwrites
* @param {string} [reason] Reason for creating this channel
* @param {string|ChannelData} [typeOrOptions='text']
* The type of the new channel, one of `text`, `voice`, `category`, `news`, or `store`. **(deprecated, use options)**
* Alternatively options for the new channel, overriding the following parameters.
* @param {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [permissionOverwrites]
* Permission overwrites **(deprecated, use options)**
* @param {string} [reason] Reason for creating this channel **(deprecated, use options)**
* @returns {Promise<CategoryChannel|TextChannel|VoiceChannel>}
* @example
* // Create a new text channel
* guild.createChannel('new-general', 'text')
* guild.createChannel('new-general', { type: 'text' })
* .then(console.log)

@@ -1006,12 +1074,28 @@ * .catch(console.error);

* // Create a new category channel with permission overwrites
* guild.createChannel('new-category', 'category', [{
* id: guild.id,
* deny: ['MANAGE_MESSAGES'],
* allow: ['SEND_MESSAGES']
* }])
* guild.createChannel('new-category', {
* type: 'category',
* permissionsOverwrites: [{
* id: guild.id,
* deny: ['MANAGE_MESSAGES'],
* allow: ['SEND_MESSAGES']
* }]
* })
* .then(console.log)
* .catch(console.error);
*/
createChannel(name, type, overwrites, reason) {
return this.client.rest.methods.createChannel(this, name, type, overwrites, reason);
createChannel(name, typeOrOptions, permissionOverwrites, reason) {
if (!typeOrOptions || (typeof typeOrOptions === 'string')) {
if (typeOrOptions) {
process.emitWarning(
'Guild#createChannel: Create channels with an options object instead of separate parameters',
'DeprecationWarning'
);
}
typeOrOptions = {
type: typeOrOptions,
permissionOverwrites,
reason,
};
}
return this.client.rest.methods.createChannel(this, name, typeOrOptions);
}

@@ -1040,2 +1124,13 @@

/**
* Edits the guild's embed.
* @param {GuildEmbedData} embed The embed for the guild
* @param {string} [reason] Reason for changing the guild's embed
* @returns {Promise<Guild>}
*/
setEmbed(embed, reason) {
return this.client.rest.methods.updateEmbed(this.id, embed, reason)
.then(() => this);
}
/**
* Creates a new role in the guild with given information.

@@ -1098,3 +1193,4 @@ * @param {RoleData} [data] The data to update the role with

deleteEmoji(emoji, reason) {
if (!(emoji instanceof Emoji)) emoji = this.emojis.get(emoji);
if (typeof emoji === 'string') emoji = this.emojis.get(emoji);
if (!(emoji instanceof Emoji)) throw new TypeError('Emoji must be either an instance of Emoji or an ID');
return this.client.rest.methods.deleteEmoji(emoji, reason);

@@ -1237,2 +1333,3 @@ }

_removeMember(guildMember) {
if (guildMember.voiceChannel) guildMember.voiceChannel.members.delete(guildMember.id);
this.members.delete(guildMember.id);

@@ -1336,3 +1433,3 @@ }

a.position - b.position :
Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber()
Long.fromString(b.id).sub(Long.fromString(a.id)).toNumber()
);

@@ -1339,0 +1436,0 @@ }

@@ -268,4 +268,4 @@ const Channel = require('./Channel');

const permissionOverwrites = this.parent.permissionOverwrites.map(overwrite => ({
deny: overwrite.deny.bitfield,
allow: overwrite.allow.bitfield,
deny: overwrite.deny,
allow: overwrite.allow,
id: overwrite.id,

@@ -280,2 +280,3 @@ type: overwrite.type,

* @typedef {Object} ChannelData
* @property {string} [type] The type of the channel (Only when creating)
* @property {string} [name] The name of the channel

@@ -287,5 +288,6 @@ * @property {number} [position] The position of the channel

* @property {number} [userLimit] The user limit of the channel
* @property {string} [parent] The parent ID of the channel
* @property {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [overwrites]
* @property {CategoryChannel|Snowflake} [parent] The parent or parent ID of the channel
* @property {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [permissionOverwrites]
* Overwrites of the channel
* @property {number} [rateLimitPerUser] The rate limit per user of the channel
*/

@@ -404,4 +406,8 @@

clone(name = this.name, withPermissions = true, withTopic = true, reason) {
return this.guild.createChannel(name, this.type, withPermissions ? this.permissionOverwrites : [], reason)
.then(channel => withTopic ? channel.setTopic(this.topic) : channel);
return this.guild.createChannel(name, {
type: this.type,
permissionOverwrites: withPermissions ? this.permissionOverwrites : undefined,
topic: withTopic ? this.topic : undefined,
reason,
});
}

@@ -408,0 +414,0 @@

@@ -354,3 +354,4 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel');

* @property {boolean} [deaf] Whether or not the member should be deafened
* @property {ChannelResolvable} [channel] Channel to move member to (if they are connected to voice)
* @property {ChannelResolvable|null} [channel] Channel to move member to (if they are connected to voice), or `null`
* if you want to kick them from voice
*/

@@ -408,3 +409,4 @@

* Moves this member to the given channel.
* @param {ChannelResolvable} channel The channel to move the member to
* @param {ChannelResolvable|null} channel Channel to move the member to, or `null` if you want to kick them from
* voice
* @returns {Promise<GuildMember>}

@@ -610,3 +612,5 @@ * @example

'GuildMember#hasPermissions is deprecated - use GuildMember#hasPermission, it now takes an array');
GuildMember.prototype.missingPermissions = util.deprecate(GuildMember.prototype.missingPermissions,
'GuildMember#missingPermissions is deprecated - use GuildMember#permissions.missing, it now takes an array');
module.exports = GuildMember;

@@ -33,2 +33,8 @@ const path = require('path');

this.lastMessage = null;
/**
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = null;
}

@@ -394,2 +400,20 @@

/**
* The Message object of the last message in the channel, if one was sent
* @type {?Message}
* @readonly
*/
get lastMessage() {
return this.messages.get(this.lastMessageID) || null;
}
/**
* The date when the last pinned message was pinned, if there was one
* @type {?Date}
* @readonly
*/
get lastPinAt() {
return this.lastPinTimestamp ? new Date(this.lastPinTimestamp) : null;
}
/**
* Creates a Message Collector

@@ -589,2 +613,4 @@ * @param {CollectorFilter} filter The filter to create the collector with

'search',
'lastMessage',
'lastPinAt',
'bulkDelete',

@@ -591,0 +617,0 @@ 'startTyping',

@@ -7,3 +7,4 @@ const PartialGuild = require('./PartialGuild');

* Represents an invitation to a guild channel.
* <warn>The only guaranteed properties are `code`, `guild` and `channel`. Other properties can be missing.</warn>
* <warn>The only guaranteed properties are `code`, `url`, `guild`, and `channel`.
* Other properties can be missing.</warn>
*/

@@ -10,0 +11,0 @@ class Invite {

@@ -169,3 +169,3 @@ const Mentions = require('./MessageMentions');

if ('editedTimestamp' 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;

@@ -172,0 +172,0 @@ if ('pinned' in data) this.pinned = data.pinned;

/**
* Represents an embed in a message (image/video preview, rich embed, etc.)
* <info>This class is only used for *recieved* embeds. If you wish to send one, use the {@link RichEmbed} class.</info>
* <info>This class is only used for *received* embeds. If you wish to send one, use the {@link RichEmbed} class.</info>
*/

@@ -5,0 +5,0 @@ class MessageEmbed {

const { ActivityFlags, Endpoints } = require('../util/Constants');
/**
* The status of this presence:
*
* * **`online`** - user is online
* * **`idle`** - user is AFK
* * **`offline`** - user is offline or invisible
* * **`dnd`** - user is in Do Not Disturb
* @typedef {string} PresenceStatus
*/
/**
* Represents a user's presence.

@@ -11,9 +21,4 @@ */

/**
* The status of the presence:
*
* * **`online`** - user is online
* * **`offline`** - user is offline or invisible
* * **`idle`** - user is AFK
* * **`dnd`** - user is in Do not Disturb
* @type {string}
* The status of this presence:
* @type {PresenceStatus}
*/

@@ -27,2 +32,11 @@ this.status = data.status || 'offline';

this.game = data.game ? new Game(data.game, this) : null;
/**
* The devices this presence is on
* @type {?object}
* @property {PresenceStatus} web
* @property {PresenceStatus} mobile
* @property {PresenceStatus} desktop
*/
this.clientStatus = data.client_status || null;
}

@@ -33,2 +47,3 @@

this.game = data.game ? new Game(data.game, this) : null;
this.clientStatus = data.client_status || null;
}

@@ -45,3 +60,6 @@

this.status === presence.status &&
this.game ? this.game.equals(presence.game) : !presence.game
(this.game ? this.game.equals(presence.game) : !presence.game) &&
this.clientStatus.web === presence.clientStatus.web &&
this.clientStatus.mobile === presence.clientStatus.mobile &&
this.clientStatus.desktop === presence.clientStatus.desktop
);

@@ -65,3 +83,7 @@ }

/**
* The type of the game status
* The type of the game status, its possible values:
* - 0: Playing
* - 1: Streaming
* - 2: Listening
* - 3: Watching
* @type {number}

@@ -68,0 +90,0 @@ */

@@ -143,6 +143,7 @@ const Attachment = require('./Attachment');

* Sets the timestamp of this embed.
* @param {Date} [timestamp=new Date()] The timestamp
* @param {Date|number} [timestamp=Date.now()] The timestamp or date
* @returns {RichEmbed} This embed
*/
setTimestamp(timestamp = new Date()) {
setTimestamp(timestamp = Date.now()) {
if (timestamp instanceof Date) timestamp = timestamp.getTime();
this.timestamp = timestamp;

@@ -240,2 +241,17 @@ return this;

/**
* The accumulated length for the embed title, description, fields, author and footer text
* @type {number}
* @readonly
*/
get length() {
return (
(this.title ? this.title.length : 0) +
(this.description ? this.description.length : 0) +
(this.fields.length >= 1 ? this.fields.reduce((prev, curr) =>
prev + curr.name.length + curr.value.length, 0) : 0) +
(this.footer ? this.footer.text.length : 0) +
(this.author ? this.author.name.length : 0));
}
/**
* Transforms the embed object to be processed.

@@ -242,0 +258,0 @@ * @returns {Object} The raw data of this embed

@@ -14,2 +14,6 @@ const GuildChannel = require('./GuildChannel');

this.type = 'text';
/**
* A collection containing the messages sent to this channel
* @type {Collection<Snowflake, Message>}
*/
this.messages = new Collection();

@@ -40,2 +44,14 @@ this._typing = new Map();

this.lastMessageID = data.last_message_id;
/**
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
/**
* The ratelimit per user for this channel
* @type {number}
*/
this.rateLimitPerUser = data.rate_limit_per_user || 0;
}

@@ -102,4 +118,16 @@

/**
* Sets the rate limit per user for this channel.
* @param {number} rateLimitPerUser The new ratelimit
* @param {string} [reason] Reason for changing the channel's ratelimits
* @returns {Promise<TextChannel>}
*/
setRateLimitPerUser(rateLimitPerUser, reason) {
return this.edit({ rateLimitPerUser }, reason);
}
// These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */
get lastMessage() {}
get lastPinAt() {}
send() { }

@@ -106,0 +134,0 @@ sendMessage() { }

@@ -137,3 +137,3 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel');

/**
* The Discord "tag" for this user
* The Discord "tag" (e.g. `hydrabolt#0001`) for this user
* @type {string}

@@ -192,3 +192,3 @@ * @readonly

get dmChannel() {
return this.client.channels.filter(c => c.type === 'dm').find(c => c.recipient.id === this.id);
return this.client.channels.find(c => c.type === 'dm' && c.recipient.id === this.id);
}

@@ -195,0 +195,0 @@

@@ -0,1 +1,2 @@

const EventEmitter = require('events');
const path = require('path');

@@ -9,4 +10,5 @@ const Util = require('../util/Util');

*/
class Webhook {
class Webhook extends EventEmitter {
constructor(client, dataOrID, token) {
super();
if (client) {

@@ -37,2 +39,3 @@ /**

* The token for the webhook
* @name Webhook#token
* @type {string}

@@ -39,0 +42,0 @@ */

@@ -226,4 +226,4 @@ const util = require('util');

*/
/* eslint-enable max-len */
findKey(propOrFn, value) {
/* eslint-enable max-len */
if (typeof propOrFn === 'string') {

@@ -230,0 +230,0 @@ if (typeof value === 'undefined') throw new Error('Value must be specified.');

@@ -27,2 +27,4 @@ exports.Package = require('../../package.json');

* requests (higher values will reduce rate-limiting errors on bad connections)
* @property {number} [retryLimit=Infinity] How many times to retry on 5XX errors
* (Infinity for indefinite amount of retries)
* @property {WSEventType[]} [disabledEvents] An array of disabled websocket events. Events in this array will not be

@@ -46,2 +48,3 @@ * processed, potentially resulting in performance improvements for larger bots. Only disable events you are

restWsBridgeTimeout: 5000,
retryLimit: Infinity,
disabledEvents: [],

@@ -146,2 +149,3 @@ restTimeOffset: 500,

search: `${base}/messages/search`,
vanityURL: `${base}/vanity-url`,
voiceRegions: `${base}/regions`,

@@ -244,8 +248,8 @@ webhooks: `${base}/webhooks`,

* The current status of the client. Here are the available statuses:
* * READY
* * CONNECTING
* * RECONNECTING
* * IDLE
* * NEARLY
* * DISCONNECTED
* * READY: 0
* * CONNECTING: 1
* * RECONNECTING: 2
* * IDLE: 3
* * NEARLY: 4
* * DISCONNECTED: 5
* @typedef {number} Status

@@ -285,2 +289,4 @@ */

CATEGORY: 4,
NEWS: 5,
STORE: 6,
};

@@ -327,2 +333,3 @@

GUILD_MEMBERS_CHUNK: 'guildMembersChunk',
GUILD_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate',
GUILD_ROLE_CREATE: 'roleCreate',

@@ -355,2 +362,3 @@ GUILD_ROLE_DELETE: 'roleDelete',

TYPING_STOP: 'typingStop',
WEBHOOKS_UPDATE: 'webhookUpdate',
DISCONNECT: 'disconnect',

@@ -399,2 +407,3 @@ RECONNECTING: 'reconnecting',

* * GUILD_MEMBERS_CHUNK
* * GUILD_INTEGRATIONS_UPDATE
* * GUILD_ROLE_CREATE

@@ -425,2 +434,3 @@ * * GUILD_ROLE_DELETE

* * RELATIONSHIP_REMOVE
* * WEBHOOKS_UPDATE
* @typedef {string} WSEventType

@@ -439,2 +449,3 @@ */

GUILD_MEMBERS_CHUNK: 'GUILD_MEMBERS_CHUNK',
GUILD_INTEGRATIONS_UPDATE: 'GUILD_INTEGRATIONS_UPDATE',
GUILD_ROLE_CREATE: 'GUILD_ROLE_CREATE',

@@ -467,2 +478,3 @@ GUILD_ROLE_DELETE: 'GUILD_ROLE_DELETE',

RELATIONSHIP_REMOVE: 'RELATIONSHIP_REMOVE',
WEBHOOKS_UPDATE: 'WEBHOOKS_UPDATE',
};

@@ -709,2 +721,3 @@

DEFAULT: 0x000000,
WHITE: 0xFFFFFF,
AQUA: 0x1ABC9C,

@@ -754,2 +767,3 @@ GREEN: 0x2ECC71,

* * UNKNOWN_EMOJI
* * UNKNOWN_WEBHOOK
* * BOT_PROHIBITED_ENDPOINT

@@ -780,2 +794,3 @@ * * BOT_ONLY_ENDPOINT

* * CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL
* * INVALID_OR_TAKEN_INVITE_CODE
* * CANNOT_EXECUTE_ON_SYSTEM_MESSAGE

@@ -802,2 +817,3 @@ * * BULK_DELETE_MESSAGE_TOO_OLD

UNKNOWN_EMOJI: 10014,
UNKNOWN_WEBHOOK: 10015,
BOT_PROHIBITED_ENDPOINT: 20001,

@@ -828,2 +844,3 @@ BOT_ONLY_ENDPOINT: 20002,

CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL: 50019,
INVALID_OR_TAKEN_INVITE_CODE: 50020,
CANNOT_EXECUTE_ON_SYSTEM_MESSAGE: 50021,

@@ -830,0 +847,0 @@ BULK_DELETE_MESSAGE_TOO_OLD: 50034,

@@ -193,2 +193,3 @@ const Constants = require('../util/Constants');

if (permission instanceof Array) return permission.map(p => this.resolve(p)).reduce((prev, p) => prev | p, 0);
if (permission instanceof Permissions) return permission.bitfield;
if (typeof permission === 'string') permission = this.FLAGS[permission];

@@ -195,0 +196,0 @@ if (typeof permission !== 'number' || permission < 0) throw new RangeError(Constants.Errors.NOT_A_PERMISSION);

@@ -22,3 +22,5 @@ const snekfetch = require('snekfetch');

const splitText = text.split(char);
if (splitText.length === 1) throw new Error('Message exceeds the max length and contains no split characters.');
if (splitText.some(chunk => chunk.length > maxLength)) {
throw new Error('Message exceeds the max length and contains no split characters.');
}
const messages = [''];

@@ -25,0 +27,0 @@ let msg = 0;

@@ -25,3 +25,3 @@ /// <reference path='index.d.ts' />

public filter: CollectorFilter;
public constructor(client: Client, filter: CollectorFilter, ) {
public constructor(client: Client, filter: CollectorFilter) {
super(client, filter);

@@ -68,4 +68,4 @@ }

public cleanup(): void {
this.client.removeListener('messageReactionAdd', this.listener);
this.client.removeListener('messageReactionAdd', this.listener as any);
}
}

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