discord-slim
Advanced tools
Comparing version 2.0.0-dev.2 to 2.0.0-dev.3
@@ -38,3 +38,3 @@ /// <reference types="node" /> | ||
on(event: 'disconnect', listener: (this: this, code: number) => void): this; | ||
on(event: 'packet', listener: (this: this, packet: { | ||
on(event: 'intent', listener: (this: this, intent: { | ||
op: number; | ||
@@ -50,3 +50,3 @@ s: number; | ||
off(event: 'disconnect', listener: (this: this, code: number) => void): this; | ||
off(event: 'packet', listener: (this: this, packet: { | ||
off(event: 'intent', listener: (this: this, intent: { | ||
op: number; | ||
@@ -62,3 +62,3 @@ s: number; | ||
once(event: 'disconnect', listener: (this: this, code: number) => void): this; | ||
once(event: 'packet', listener: (this: this, packet: { | ||
once(event: 'intent', listener: (this: this, intent: { | ||
op: number; | ||
@@ -65,0 +65,0 @@ s: number; |
@@ -331,1 +331,4 @@ 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 InteractionResponseFlags { | ||
EPHEMERAL = 64 | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.Events = 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.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.Events = exports.OPCodes = exports.TokenTypes = 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'; | ||
@@ -366,1 +366,5 @@ var TokenTypes; | ||
})(InteractionResponseTypes = exports.InteractionResponseTypes || (exports.InteractionResponseTypes = {})); | ||
var InteractionResponseFlags; | ||
(function (InteractionResponseFlags) { | ||
InteractionResponseFlags[InteractionResponseFlags["EPHEMERAL"] = 64] = "EPHEMERAL"; | ||
})(InteractionResponseFlags = exports.InteractionResponseFlags || (exports.InteractionResponseFlags = {})); |
@@ -544,3 +544,3 @@ import type * as helpers from './helpers'; | ||
allowed_mentions?: AllowedMentions; | ||
flags?: number; | ||
flags?: helpers.InteractionResponseFlags; | ||
}; | ||
@@ -547,0 +547,0 @@ export declare type MessageInteraction = { |
{ | ||
"name": "discord-slim", | ||
"version": "2.0.0-dev.2", | ||
"version": "2.0.0-dev.3", | ||
"description": "Lightweight Discord client for Node.js.", | ||
@@ -5,0 +5,0 @@ "author": "Hanabishi", |
@@ -11,2 +11,3 @@ # Discord Slim | ||
- Actions is now independent from the client. | ||
- Uses new Discord API version (v8) with slash commands support | ||
@@ -25,14 +26,15 @@ ### Support & suggestions server | ||
``` | ||
## Usage example | ||
### Initial setup | ||
```js | ||
const | ||
Discord = require('discord-slim'), | ||
Actions = Discord.Actions, | ||
Events = Discord.Helpers.Events, | ||
Intents = Discord.Helpers.Intents, | ||
client = new Discord.Client(), | ||
authorization = new Discord.Authorization('token'), | ||
requestOptions = { authorization }; | ||
client = new Discord.Client(); | ||
// Authorization object. Required for client and actions. | ||
const authorization = new Discord.Authorization('token'); | ||
// Basic setup to control client operation. | ||
// You probably want to use such code for every bot. | ||
client.on('connect', () => console.log('Connection established.')); | ||
@@ -44,2 +46,22 @@ client.on('disconnect', (code) => console.error(`Disconnect. (${code})`)); | ||
// Request options for actions | ||
const requestOptions = { | ||
// Include authorization, it is required for most actions. | ||
authorization, | ||
// Rate limit behavior configuration. | ||
// This options is not required, but you probably want to care about rate limit. | ||
rateLimit: { | ||
// Set how many times to retry after hitting rate limit. Default: 5. | ||
retryCount: 1, | ||
// Just fallback timeout option when server not provided 'retry_after' value. Default: 1000 ms. | ||
retryTimeout: 1000, | ||
// Rate limit hit callback | ||
callback: (response, attempts) => console.log(`${response.message} Global: ${response.global}. Cooldown: ${response.retry_after} sec. Attempt: ${attempts}.`), | ||
}, | ||
}; | ||
``` | ||
### Basic message response | ||
```js | ||
client.events.on(Events.MESSAGE_CREATE, (message) => { | ||
@@ -60,3 +82,37 @@ if(message.author.id == client.user.id) return; | ||
### Using slash commands | ||
Note: slash commands requires `applications.commands` scope. Read details in [docs](https://discord.com/developers/docs/interactions/slash-commands). | ||
```js | ||
// Create a command in your guild(s). | ||
client.events.on(Events.GUILD_CREATE, (guild) => { | ||
Actions.Application.CreateGuildCommand(client.user.id, guild.id, { | ||
name: 'echo', | ||
description: 'Test slash command.', | ||
options: [ | ||
{ | ||
type: Discord.Helpers.ApplicationCommandOptionTypes.STRING, | ||
name: 'text', | ||
description: 'Echo message text.', | ||
required: true, | ||
}, | ||
], | ||
}, requestOptions); | ||
}); | ||
// Respond to interaction event. | ||
client.events.on(Events.INTERACTION_CREATE, (interaction) => { | ||
if(!(interaction.data && interaction.data.name == 'echo')) return; | ||
Actions.Application.CreateInteractionResponse(interaction.id, interaction.token, { | ||
type: Discord.Helpers.InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: interaction.data.options[0].value, | ||
flags: Discord.Helpers.InteractionResponseFlags.EPHEMERAL, | ||
}, | ||
}, requestOptions); | ||
}); | ||
client.Connect(authorization, Intents.GUILDS); | ||
``` | ||
## Build from source | ||
Install `typescript` package from `npm` and run `tsc`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120079
2495
115