Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discord-slim

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-slim - npm Package Compare versions

Comparing version 2.0.0-dev.7 to 2.0.0-dev.8

8

dist/actions.d.ts

@@ -42,4 +42,4 @@ /// <reference types="node" />

EditPermissions: (channel_id: string, overwrite_id: string, params: {
allow: helpers.Permissions;
deny: helpers.Permissions;
allow: string;
deny: string;
type: helpers.PermissionsOverwriteTypes;

@@ -225,3 +225,3 @@ }, requestOptions?: RequestOptions | undefined) => Promise<null>;

name?: string | undefined;
permissions?: helpers.Permissions | undefined;
permissions?: string | undefined;
color?: number | undefined;

@@ -233,3 +233,3 @@ hoist?: boolean | undefined;

name?: string | undefined;
permissions?: helpers.Permissions | undefined;
permissions?: string | undefined;
color?: number | undefined;

@@ -236,0 +236,0 @@ hoist?: boolean | undefined;

@@ -6,3 +6,3 @@ /// <reference types="node" />

import { EventHandler, EventTypes } from './events';
import type { User, Activity } from './types';
import type { User } from './types';
export declare class Client extends EventEmitter {

@@ -52,4 +52,8 @@ private _sessionId?;

since: number | null;
activities: Activity[] | null;
status: 'online' | 'dnd' | 'idle' | 'invisible' | 'offline';
activities: {
name: string;
type: helpers.ActivityTypes;
url?: string;
}[] | null;
status: helpers.StatusTypes;
afk: boolean;

@@ -60,7 +64,15 @@ }) => void;

}
export declare enum ClientEvents {
CONNECT = "connect",
DISCONNECT = "disconnect",
INTENT = "intent",
WARN = "warn",
ERROR = "error",
FATAL = "fatal"
}
export interface Client {
on(event: 'connect', listener: (this: this) => void): this;
on(event: 'disconnect', listener: (this: this, code: number) => void): this;
on(event: 'intent', listener: (this: this, intent: {
op: number;
on(event: ClientEvents.CONNECT, listener: (this: this) => void): this;
on(event: ClientEvents.DISCONNECT, listener: (this: this, code: number) => void): this;
on(event: ClientEvents.INTENT, listener: (this: this, intent: {
op: 0;
s: number;

@@ -70,9 +82,9 @@ t: string;

}) => void): this;
on(event: 'warn', listener: (this: this, message: string) => void): this;
on(event: 'error', listener: (this: this, message: string) => void): this;
on(event: 'fatal', listener: (this: this, message: string) => void): this;
off(event: 'connect', listener: (this: this) => void): this;
off(event: 'disconnect', listener: (this: this, code: number) => void): this;
off(event: 'intent', listener: (this: this, intent: {
op: number;
on(event: ClientEvents.WARN, listener: (this: this, message: string) => void): this;
on(event: ClientEvents.ERROR, listener: (this: this, error: Error) => void): this;
on(event: ClientEvents.FATAL, listener: (this: this, message: string) => void): this;
off(event: ClientEvents.CONNECT, listener: (this: this) => void): this;
off(event: ClientEvents.DISCONNECT, listener: (this: this, code: number) => void): this;
off(event: ClientEvents.INTENT, listener: (this: this, intent: {
op: 0;
s: number;

@@ -82,9 +94,9 @@ t: string;

}) => void): this;
off(event: 'warn', listener: (this: this, message: string) => void): this;
off(event: 'error', listener: (this: this, message: string) => void): this;
off(event: 'fatal', listener: (this: this, message: string) => void): this;
once(event: 'connect', listener: (this: this) => void): this;
once(event: 'disconnect', listener: (this: this, code: number) => void): this;
once(event: 'intent', listener: (this: this, intent: {
op: number;
off(event: ClientEvents.WARN, listener: (this: this, message: string) => void): this;
off(event: ClientEvents.ERROR, listener: (this: this, error: Error) => void): this;
off(event: ClientEvents.FATAL, listener: (this: this, message: string) => void): this;
once(event: ClientEvents.CONNECT, listener: (this: this) => void): this;
once(event: ClientEvents.DISCONNECT, listener: (this: this, code: number) => void): this;
once(event: ClientEvents.INTENT, listener: (this: this, intent: {
op: 0;
s: number;

@@ -94,5 +106,5 @@ t: string;

}) => void): this;
once(event: 'warn', listener: (this: this, message: string) => void): this;
once(event: 'error', listener: (this: this, message: string) => void): this;
once(event: 'fatal', listener: (this: this, message: string) => void): this;
once(event: ClientEvents.WARN, listener: (this: this, message: string) => void): this;
once(event: ClientEvents.ERROR, listener: (this: this, error: Error) => void): this;
once(event: ClientEvents.FATAL, listener: (this: this, message: string) => void): this;
}

@@ -25,3 +25,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
exports.ClientEvents = exports.Client = void 0;
const ws_1 = __importDefault(require("ws"));

@@ -111,6 +111,5 @@ const events_1 = require("events");

this._identify = () => {
var _a, _b, _c;
this._sessionId ?
this._send(6, {
token: (_a = this._auth) === null || _a === void 0 ? void 0 : _a.authorization.token,
token: this._auth?.authorization.token,
session_id: this._sessionId,

@@ -120,5 +119,5 @@ seq: this._lastSequence,

this._send(2, {
token: (_b = this._auth) === null || _b === void 0 ? void 0 : _b.authorization.token,
token: this._auth?.authorization.token,
properties: { $os: 'linux', $browser: 'bot', $device: 'bot' },
intents: (_c = this._intents) !== null && _c !== void 0 ? _c : helpers.Intents.SYSTEM_ONLY,
intents: this._intents ?? helpers.Intents.SYSTEM_ONLY,
shard: this._shard,

@@ -184,1 +183,10 @@ });

exports.Client = Client;
var ClientEvents;
(function (ClientEvents) {
ClientEvents["CONNECT"] = "connect";
ClientEvents["DISCONNECT"] = "disconnect";
ClientEvents["INTENT"] = "intent";
ClientEvents["WARN"] = "warn";
ClientEvents["ERROR"] = "error";
ClientEvents["FATAL"] = "fatal";
})(ClientEvents = exports.ClientEvents || (exports.ClientEvents = {}));
export declare const HOST: "https://discord.com", API: "https://discord.com/api", API_VERSION = 8, API_PATH: "https://discord.com/api/v8", CDN = "https://cdn.discordapp.com";
export declare enum TokenTypes {
Bot = "Bot",
Bearer = "Bearer"
}
export declare enum OPCodes {
DISPATCH = 0,
HEARTBEAT = 1,
IDENTIFY = 2,
PRESENCE_UPDATE = 3,
VOICE_STATE_UPDATE = 4,
RESUME = 6,
RECONNECT = 7,
REQUEST_GUILD_MEMBERS = 8,
INVALID_SESSION = 9,
HELLO = 10,
HEARTBEAT_ACK = 11
}
export declare enum Permissions {
NO_PERMISSIONS = 0,
CREATE_INSTANT_INVITE = 1,
KICK_MEMBERS = 2,
BAN_MEMBERS = 4,
ADMINISTRATOR = 8,
MANAGE_CHANNELS = 16,
MANAGE_GUILD = 32,
ADD_REACTIONS = 64,
VIEW_AUDIT_LOG = 128,
PRIORITY_SPEAKER = 256,
STREAM = 512,
VIEW_CHANNEL = 1024,
SEND_MESSAGES = 2048,
SEND_TTS_MESSAGES = 4096,
MANAGE_MESSAGES = 8192,
EMBED_LINKS = 16384,
ATTACH_FILES = 32768,
READ_MESSAGE_HISTORY = 65536,
MENTION_EVERYONE = 131072,
USE_EXTERNAL_EMOJIS = 262144,
VIEW_GUILD_INSIGHTS = 524288,
CONNECT = 1048576,
SPEAK = 2097152,
MUTE_MEMBERS = 4194304,
DEAFEN_MEMBERS = 8388608,
MOVE_MEMBERS = 16777216,
USE_VAD = 33554432,
CHANGE_NICKNAME = 67108864,
MANAGE_NICKNAMES = 134217728,
MANAGE_ROLES = 268435456,
MANAGE_WEBHOOKS = 536870912,
MANAGE_EMOJIS = 1073741824,
REQUEST_TO_SPEAK = 4294967296
}
export declare const Permissions: {
readonly NO_PERMISSIONS: 0n;
readonly CREATE_INSTANT_INVITE: 1n;
readonly KICK_MEMBERS: 2n;
readonly BAN_MEMBERS: 4n;
readonly ADMINISTRATOR: 8n;
readonly MANAGE_CHANNELS: 16n;
readonly MANAGE_GUILD: 32n;
readonly ADD_REACTIONS: 64n;
readonly VIEW_AUDIT_LOG: 128n;
readonly PRIORITY_SPEAKER: 256n;
readonly STREAM: 512n;
readonly VIEW_CHANNEL: 1024n;
readonly SEND_MESSAGES: 2048n;
readonly SEND_TTS_MESSAGES: 4096n;
readonly MANAGE_MESSAGES: 8192n;
readonly EMBED_LINKS: 16384n;
readonly ATTACH_FILES: 32768n;
readonly READ_MESSAGE_HISTORY: 65536n;
readonly MENTION_EVERYONE: 131072n;
readonly USE_EXTERNAL_EMOJIS: 262144n;
readonly VIEW_GUILD_INSIGHTS: 524288n;
readonly CONNECT: 1048576n;
readonly SPEAK: 2097152n;
readonly MUTE_MEMBERS: 4194304n;
readonly DEAFEN_MEMBERS: 8388608n;
readonly MOVE_MEMBERS: 16777216n;
readonly USE_VAD: 33554432n;
readonly CHANGE_NICKNAME: 67108864n;
readonly MANAGE_NICKNAMES: 134217728n;
readonly MANAGE_ROLES: 268435456n;
readonly MANAGE_WEBHOOKS: 536870912n;
readonly MANAGE_EMOJIS: 1073741824n;
readonly REQUEST_TO_SPEAK: 4294967296n;
};
export declare enum Intents {

@@ -226,2 +209,9 @@ SYSTEM_ONLY = 0,

}
export declare enum StatusTypes {
ONLINE = "online",
DO_NOT_DISTURB = "dnd",
IDLE = "idle",
INVISIBLE = "invisible",
OFFLINE = "offline"
}
export declare enum WidgetStyleOptions {

@@ -228,0 +218,0 @@ SHIELD = "shield",

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InteractionResponseFlags = exports.InteractionResponseTypes = exports.InteractionTypes = exports.ApplicationCommandOptionTypes = exports.ActivityFlags = exports.WebhookTypes = exports.VisibilityTypes = exports.PremiumTypes = exports.UserFlags = exports.WidgetStyleOptions = exports.ActivityTypes = exports.TargetUserTypes = exports.PremiumTier = exports.IntegrationExpireBehaviors = exports.GuildFeatures = exports.SystemChannelFlags = exports.VerificationLevel = exports.MFA_Level = exports.ExplicitContentFilterLevel = exports.DefaultMessageNotificationLevel = exports.AllowedMentionTypes = exports.PermissionsOverwriteTypes = exports.MessageStickerFormatTypes = exports.MessageFlags = exports.MessageActivityTypes = exports.MessageTypes = exports.ChannelTypes = exports.AuditLogEvents = exports.Intents = exports.Permissions = exports.OPCodes = exports.TokenTypes = exports.CDN = exports.API_PATH = exports.API_VERSION = exports.API = exports.HOST = void 0;
exports.InteractionResponseFlags = exports.InteractionResponseTypes = exports.InteractionTypes = exports.ApplicationCommandOptionTypes = exports.ActivityFlags = exports.WebhookTypes = exports.VisibilityTypes = exports.PremiumTypes = exports.UserFlags = exports.WidgetStyleOptions = exports.StatusTypes = exports.ActivityTypes = exports.TargetUserTypes = exports.PremiumTier = exports.IntegrationExpireBehaviors = exports.GuildFeatures = exports.SystemChannelFlags = exports.VerificationLevel = exports.MFA_Level = exports.ExplicitContentFilterLevel = exports.DefaultMessageNotificationLevel = exports.AllowedMentionTypes = exports.PermissionsOverwriteTypes = exports.MessageStickerFormatTypes = exports.MessageFlags = exports.MessageActivityTypes = exports.MessageTypes = exports.ChannelTypes = exports.AuditLogEvents = exports.Intents = exports.Permissions = exports.CDN = exports.API_PATH = exports.API_VERSION = exports.API = exports.HOST = void 0;
exports.HOST = 'https://discord.com', exports.API = `${exports.HOST}/api`, exports.API_VERSION = 8, exports.API_PATH = `${exports.API}/v${exports.API_VERSION}`, exports.CDN = 'https://cdn.discordapp.com';
var TokenTypes;
(function (TokenTypes) {
TokenTypes["Bot"] = "Bot";
TokenTypes["Bearer"] = "Bearer";
})(TokenTypes = exports.TokenTypes || (exports.TokenTypes = {}));
var OPCodes;
(function (OPCodes) {
OPCodes[OPCodes["DISPATCH"] = 0] = "DISPATCH";
OPCodes[OPCodes["HEARTBEAT"] = 1] = "HEARTBEAT";
OPCodes[OPCodes["IDENTIFY"] = 2] = "IDENTIFY";
OPCodes[OPCodes["PRESENCE_UPDATE"] = 3] = "PRESENCE_UPDATE";
OPCodes[OPCodes["VOICE_STATE_UPDATE"] = 4] = "VOICE_STATE_UPDATE";
OPCodes[OPCodes["RESUME"] = 6] = "RESUME";
OPCodes[OPCodes["RECONNECT"] = 7] = "RECONNECT";
OPCodes[OPCodes["REQUEST_GUILD_MEMBERS"] = 8] = "REQUEST_GUILD_MEMBERS";
OPCodes[OPCodes["INVALID_SESSION"] = 9] = "INVALID_SESSION";
OPCodes[OPCodes["HELLO"] = 10] = "HELLO";
OPCodes[OPCodes["HEARTBEAT_ACK"] = 11] = "HEARTBEAT_ACK";
})(OPCodes = exports.OPCodes || (exports.OPCodes = {}));
var Permissions;
(function (Permissions) {
Permissions[Permissions["NO_PERMISSIONS"] = 0] = "NO_PERMISSIONS";
Permissions[Permissions["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
Permissions[Permissions["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
Permissions[Permissions["BAN_MEMBERS"] = 4] = "BAN_MEMBERS";
Permissions[Permissions["ADMINISTRATOR"] = 8] = "ADMINISTRATOR";
Permissions[Permissions["MANAGE_CHANNELS"] = 16] = "MANAGE_CHANNELS";
Permissions[Permissions["MANAGE_GUILD"] = 32] = "MANAGE_GUILD";
Permissions[Permissions["ADD_REACTIONS"] = 64] = "ADD_REACTIONS";
Permissions[Permissions["VIEW_AUDIT_LOG"] = 128] = "VIEW_AUDIT_LOG";
Permissions[Permissions["PRIORITY_SPEAKER"] = 256] = "PRIORITY_SPEAKER";
Permissions[Permissions["STREAM"] = 512] = "STREAM";
Permissions[Permissions["VIEW_CHANNEL"] = 1024] = "VIEW_CHANNEL";
Permissions[Permissions["SEND_MESSAGES"] = 2048] = "SEND_MESSAGES";
Permissions[Permissions["SEND_TTS_MESSAGES"] = 4096] = "SEND_TTS_MESSAGES";
Permissions[Permissions["MANAGE_MESSAGES"] = 8192] = "MANAGE_MESSAGES";
Permissions[Permissions["EMBED_LINKS"] = 16384] = "EMBED_LINKS";
Permissions[Permissions["ATTACH_FILES"] = 32768] = "ATTACH_FILES";
Permissions[Permissions["READ_MESSAGE_HISTORY"] = 65536] = "READ_MESSAGE_HISTORY";
Permissions[Permissions["MENTION_EVERYONE"] = 131072] = "MENTION_EVERYONE";
Permissions[Permissions["USE_EXTERNAL_EMOJIS"] = 262144] = "USE_EXTERNAL_EMOJIS";
Permissions[Permissions["VIEW_GUILD_INSIGHTS"] = 524288] = "VIEW_GUILD_INSIGHTS";
Permissions[Permissions["CONNECT"] = 1048576] = "CONNECT";
Permissions[Permissions["SPEAK"] = 2097152] = "SPEAK";
Permissions[Permissions["MUTE_MEMBERS"] = 4194304] = "MUTE_MEMBERS";
Permissions[Permissions["DEAFEN_MEMBERS"] = 8388608] = "DEAFEN_MEMBERS";
Permissions[Permissions["MOVE_MEMBERS"] = 16777216] = "MOVE_MEMBERS";
Permissions[Permissions["USE_VAD"] = 33554432] = "USE_VAD";
Permissions[Permissions["CHANGE_NICKNAME"] = 67108864] = "CHANGE_NICKNAME";
Permissions[Permissions["MANAGE_NICKNAMES"] = 134217728] = "MANAGE_NICKNAMES";
Permissions[Permissions["MANAGE_ROLES"] = 268435456] = "MANAGE_ROLES";
Permissions[Permissions["MANAGE_WEBHOOKS"] = 536870912] = "MANAGE_WEBHOOKS";
Permissions[Permissions["MANAGE_EMOJIS"] = 1073741824] = "MANAGE_EMOJIS";
Permissions[Permissions["REQUEST_TO_SPEAK"] = 4294967296] = "REQUEST_TO_SPEAK";
})(Permissions = exports.Permissions || (exports.Permissions = {}));
exports.Permissions = {
NO_PERMISSIONS: 0x000000000n,
CREATE_INSTANT_INVITE: 0x000000001n,
KICK_MEMBERS: 0x000000002n,
BAN_MEMBERS: 0x000000004n,
ADMINISTRATOR: 0x000000008n,
MANAGE_CHANNELS: 0x000000010n,
MANAGE_GUILD: 0x000000020n,
ADD_REACTIONS: 0x000000040n,
VIEW_AUDIT_LOG: 0x000000080n,
PRIORITY_SPEAKER: 0x000000100n,
STREAM: 0x000000200n,
VIEW_CHANNEL: 0x000000400n,
SEND_MESSAGES: 0x000000800n,
SEND_TTS_MESSAGES: 0x000001000n,
MANAGE_MESSAGES: 0x000002000n,
EMBED_LINKS: 0x000004000n,
ATTACH_FILES: 0x000008000n,
READ_MESSAGE_HISTORY: 0x000010000n,
MENTION_EVERYONE: 0x000020000n,
USE_EXTERNAL_EMOJIS: 0x000040000n,
VIEW_GUILD_INSIGHTS: 0x000080000n,
CONNECT: 0x000100000n,
SPEAK: 0x000200000n,
MUTE_MEMBERS: 0x000400000n,
DEAFEN_MEMBERS: 0x000800000n,
MOVE_MEMBERS: 0x001000000n,
USE_VAD: 0x002000000n,
CHANGE_NICKNAME: 0x004000000n,
MANAGE_NICKNAMES: 0x008000000n,
MANAGE_ROLES: 0x010000000n,
MANAGE_WEBHOOKS: 0x020000000n,
MANAGE_EMOJIS: 0x040000000n,
REQUEST_TO_SPEAK: 0x100000000n,
};
var Intents;

@@ -251,2 +231,10 @@ (function (Intents) {

})(ActivityTypes = exports.ActivityTypes || (exports.ActivityTypes = {}));
var StatusTypes;
(function (StatusTypes) {
StatusTypes["ONLINE"] = "online";
StatusTypes["DO_NOT_DISTURB"] = "dnd";
StatusTypes["IDLE"] = "idle";
StatusTypes["INVISIBLE"] = "invisible";
StatusTypes["OFFLINE"] = "offline";
})(StatusTypes = exports.StatusTypes || (exports.StatusTypes = {}));
var WidgetStyleOptions;

@@ -253,0 +241,0 @@ (function (WidgetStyleOptions) {

@@ -1,3 +0,3 @@

export { Client } from './client';
export { Authorization } from './request';
export { Client, ClientEvents } from './client';
export { Authorization, TokenTypes } from './request';
export { Events } from './events';

@@ -4,0 +4,0 @@ export * as Actions from './actions';

@@ -22,7 +22,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Helpers = exports.Actions = exports.Events = exports.Authorization = exports.Client = void 0;
exports.Helpers = exports.Actions = exports.Events = exports.TokenTypes = exports.Authorization = exports.ClientEvents = exports.Client = void 0;
var client_1 = require("./client");
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
Object.defineProperty(exports, "ClientEvents", { enumerable: true, get: function () { return client_1.ClientEvents; } });
var request_1 = require("./request");
Object.defineProperty(exports, "Authorization", { enumerable: true, get: function () { return request_1.Authorization; } });
Object.defineProperty(exports, "TokenTypes", { enumerable: true, get: function () { return request_1.TokenTypes; } });
var events_1 = require("./events");

@@ -29,0 +31,0 @@ Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return events_1.Events; } });

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

import { TokenTypes } from './helpers';
export declare enum TokenTypes {
BOT = "Bot",
BEARER = "Bearer"
}
export declare class Authorization {

@@ -12,2 +15,3 @@ private _type;

set token(value: string);
get value(): string;
toString: () => string;

@@ -24,13 +28,5 @@ }

global: boolean;
}, attempts: number) => {};
}, attempts: number) => void;
};
};
export declare const Request: (method: string, endpoint: string, options?: RequestOptions | undefined, data?: string | object | null | undefined) => Promise<any>;
export declare type RequestResult = {
code: number;
data?: string;
};
export declare type RequestError = {
code: number;
response?: object;
};

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Request = exports.Authorization = void 0;
exports.Request = exports.Authorization = exports.TokenTypes = void 0;
const https_1 = __importDefault(require("https"));

@@ -12,9 +12,13 @@ const util_1 = require("./util");

const DEFAULT_CONNECTION_TIMEOUT = 5000, DEFAULT_RETRY_COUNT = 5;
var TokenTypes;
(function (TokenTypes) {
TokenTypes["BOT"] = "Bot";
TokenTypes["BEARER"] = "Bearer";
})(TokenTypes = exports.TokenTypes || (exports.TokenTypes = {}));
class Authorization {
constructor(token, type) {
constructor(token, type = TokenTypes.BOT) {
this._update = () => this._cache = `${this._type} ${this._token}`;
this.toString = () => this._cache;
this._type = type !== null && type !== void 0 ? type : helpers_1.TokenTypes.Bot;
this._token = token;
this._cache = '';
this._type = type;
this._update();

@@ -30,2 +34,4 @@ }

;
get value() { return this._cache; }
;
}

@@ -35,44 +41,40 @@ exports.Authorization = Authorization;

const Request = (method, endpoint, options, data) => {
var _a;
let content;
const headers = {};
if (data) {
if (typeof data == 'string') {
headers["Content-Type"] = "application/x-www-form-urlencoded";
headers["Content-Length"] = Buffer.byteLength(content = data);
}
else {
headers["Content-Type"] = "application/json";
headers["Content-Length"] = Buffer.byteLength(content = JSON.stringify(data));
}
}
if (options?.authorization)
headers["Authorization"] = options.authorization.toString();
const requestOptions = {
method: method,
timeout: (_a = options === null || options === void 0 ? void 0 : options.connectionTimeout) !== null && _a !== void 0 ? _a : DEFAULT_CONNECTION_TIMEOUT,
headers: {
...data && ((typeof data == 'string') ?
{ 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(content = data) } :
{ 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(content = JSON.stringify(data)) }),
...(options === null || options === void 0 ? void 0 : options.authorization) && { 'Authorization': options.authorization.toString() },
},
method,
headers,
timeout: options?.connectionTimeout ?? DEFAULT_CONNECTION_TIMEOUT,
};
return new Promise((resolve, reject) => {
var _a, _b;
const URL = helpers_1.API_PATH + endpoint, retryCount = (_b = (_a = options === null || options === void 0 ? void 0 : options.rateLimit) === null || _a === void 0 ? void 0 : _a.retryCount) !== null && _b !== void 0 ? _b : DEFAULT_RETRY_COUNT;
const URL = helpers_1.API_PATH + endpoint, retryCount = options?.rateLimit?.retryCount ?? DEFAULT_RETRY_COUNT;
let attempts = 0;
const RequestResult = (result) => {
var _a, _b;
const code = result.code;
if ((code >= 200) && (code < 300)) {
resolve(util_1.SafeJsonParse(result.data));
}
else if ((code >= 400) && (code < 500)) {
const TryRequest = async () => {
const result = await HttpsRequest(URL, requestOptions, content), code = result.code;
if ((code >= 200) && (code < 300))
return resolve(util_1.SafeJsonParse(result.data));
if ((code >= 400) && (code < 500)) {
const response = util_1.SafeJsonParse(result.data);
if (code == 429) {
attempts++;
(_b = (_a = options === null || options === void 0 ? void 0 : options.rateLimit) === null || _a === void 0 ? void 0 : _a.callback) === null || _b === void 0 ? void 0 : _b.call(_a, response, attempts);
if (response.retry_after && (attempts < retryCount))
setTimeout(TryRequest, Math.ceil(Number(response.retry_after) * 1000));
else
RequestError({ code, response });
}
else {
RequestError({ code, response });
}
if (code != 429)
return reject({ code, response });
attempts++;
options?.rateLimit?.callback?.(response, attempts);
return (response.retry_after && (attempts < retryCount)) ?
setTimeout(TryRequest, Math.ceil(Number(response.retry_after) * 1000)) :
reject({ code, response });
}
else {
RequestError({ code });
}
reject({ code });
};
const RequestError = (error) => reject(error);
const TryRequest = () => HttpsRequest(URL, requestOptions, content).then(RequestResult).catch(RequestError);
TryRequest();

@@ -85,5 +87,5 @@ });

const request = https_1.default.request(url, options, (response) => {
if (response.statusCode == null)
if (!response.statusCode)
return reject('Unknown response.');
const ReturnResult = (result) => { var _a; return resolve({ code: (_a = response.statusCode) !== null && _a !== void 0 ? _a : 0, data: result }); };
const ReturnResult = (result) => resolve({ code: response.statusCode, data: result });
const chunks = [];

@@ -90,0 +92,0 @@ let totalLength = 0;

@@ -452,3 +452,3 @@ import type * as helpers from './helpers';

position: number;
permissions: number;
permissions: string;
managed: boolean;

@@ -535,3 +535,3 @@ mentionable: boolean;

name: string;
value?: helpers.ApplicationCommandOptionTypes;
value?: string | number | boolean | User | Channel | Role;
options?: ApplicationCommandInteractionDataOption[];

@@ -561,3 +561,3 @@ };

guild_id?: string;
status?: 'online' | 'dnd' | 'idle' | 'offline';
status?: helpers.StatusTypes;
activities?: Activity[];

@@ -564,0 +564,0 @@ client_status?: ClientStatus;

{
"name": "discord-slim",
"version": "2.0.0-dev.7",
"version": "2.0.0-dev.8",
"description": "Lightweight Discord bot API for Node.js.",

@@ -22,3 +22,3 @@ "author": "Hanabishi",

"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},

@@ -25,0 +25,0 @@ "files": [

# Discord Slim
[![npm](https://img.shields.io/npm/v/discord-slim/dev?style=for-the-badge)](https://www.npmjs.com/package/discord-slim/v/dev)
Lightweight **Discord** client for **Node.js**.
Provides access to Discord client gateway and API for bots.
Very minimalistic way without excessive abstractions and dependencies. Also with very low resources usage.
### V2 IS UNDER DEVELOPMENT!

@@ -18,3 +25,3 @@ Contains breaking changes and incompatible with V1.

## Before you start
### **Node.js** 12+ is required!
### **Node.js** 14+ is required!
Make sure you have some understaning of **[Discord API](https://discordapp.com/developers/docs)**.

@@ -31,3 +38,3 @@

```js
const { Client, Authorization, Events, Actions, Helpers } = require('discord-slim');
const { Client, ClientEvents, Authorization, Events, Actions, Helpers } = require('discord-slim');

@@ -37,7 +44,7 @@ // Basic setup to control client operation.

const client = new Client();
client.on('connect', () => console.log('Connection established.'));
client.on('disconnect', (code) => console.error(`Disconnect. (${code})`));
client.on('warn', console.warn);
client.on('error', console.error);
client.on('fatal', (e) => { console.error(e); process.exit(1); });
client.on(ClientEvents.CONNECT, () => console.log('Connection established.'));
client.on(ClientEvents.DISCONNECT, (code) => console.error(`Disconnect. (${code})`));
client.on(ClientEvents.WARN, console.warn);
client.on(ClientEvents.ERROR, console.error);
client.on(ClientEvents.FATAL, (e) => { console.error(e); process.exit(1); });

@@ -64,4 +71,6 @@ // Authorization object. Required for client and actions.

// Start the client connection.
client.Connect(authorization, Helpers.Intents.GUILDS | Helpers.Intents.GUILD_MESSAGES);
```
You can read about intents [here](https://discordapp.com/developers/docs/topics/gateway#gateway-intents).

@@ -72,3 +81,4 @@ ### Basic message response

if(message.author.id == client.user.id) return;
if(message.content.toLowerCase().indexOf('hello bot') < 0) return;
// Check that the message contains phrases like "hello bot" or "hi bot"
if(message.content.search(/(^|\s)h(ello|i)(\s|\s.*\s)bot($|\s)/i) < 0) return;
Actions.Message.Create(message.channel_id, {

@@ -96,3 +106,3 @@ content: `Hi, <@${message.author.id}>!`,

afk: false,
status: 'online',
status: Helpers.StatusTypes.ONLINE,
});

@@ -99,0 +109,0 @@ });

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