Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1ce9f24
Add user commands
retrouser955 Aug 25, 2024
e4de85c
assign contexts to application command constructor
retrouser955 Aug 25, 2024
6473441
add context type to commandinteraction
retrouser955 Aug 25, 2024
431381d
Add context constants
retrouser955 Aug 25, 2024
743ac7e
Format: ApplicationCommandContextType
retrouser955 Aug 25, 2024
d58b66c
add testing for user installable
retrouser955 Aug 25, 2024
b5f05a3
Fix: user installables not registering properly
retrouser955 Aug 25, 2024
7247cbf
Add integration_types to ApplicationCommandCreateOptions type
retrouser955 Aug 25, 2024
8c0f31b
make the example more verbose
retrouser955 Aug 25, 2024
d15710d
add a warning to the example
retrouser955 Aug 25, 2024
0295152
chore: lint
retrouser955 Aug 25, 2024
f1f4733
Update typings to be optional
retrouser955 Aug 25, 2024
df8a692
Update index.d.ts
retrouser955 Aug 26, 2024
bdf0330
chore: lint
retrouser955 Aug 26, 2024
5b500ea
Merge branch 'dev' of https://github.com/retrouser955/eris into dev
retrouser955 Aug 26, 2024
b052b0f
alphabetical order
retrouser955 Aug 26, 2024
c0c23d9
remove spacing
retrouser955 Aug 26, 2024
1a81f4b
fix: spacing yet again
retrouser955 Aug 26, 2024
8e566bf
Fix: Missing guild prop && Chore: lint
retrouser955 Aug 26, 2024
19ac5e6
remove magic number
retrouser955 Aug 26, 2024
0c8a24a
update types
retrouser955 Aug 26, 2024
2afdb14
sort properties
retrouser955 Aug 27, 2024
ac00f71
Use a Guild instance
retrouser955 Aug 27, 2024
1cc3695
enhance user command example
Aug 27, 2024
a5fd831
fix: Guild not in cache on user-installables
retrouser955 Aug 29, 2024
62c2f9a
wrote guild assignment more efficiently
retrouser955 Aug 29, 2024
5d5a5ff
chore: lint
retrouser955 Aug 29, 2024
5bc39b4
Merge branch 'dev' of https://github.com/abalabahaha/eris into 1532
bsian03 Aug 31, 2024
adfa5af
lint
bsian03 Aug 31, 2024
03badc8
fix(typings): Type mismatch between discord and lib
retrouser955 Aug 31, 2024
164dab6
Merge branch 'dev' of https://github.com/retrouser955/eris into dev
retrouser955 Aug 31, 2024
f212f2f
chore(add types)
retrouser955 Sep 25, 2024
fd9abb1
chore(format)
retrouser955 Sep 25, 2024
89689e8
Merge branch 'abalabahaha:dev' into dev
retrouser955 Sep 26, 2024
ed04a28
no constructor for autocomplete
retrouser955 Oct 6, 2024
89ea9d1
assign only data.guild
retrouser955 Oct 9, 2024
7fd0d80
revert
retrouser955 Oct 15, 2024
e661cda
Merge branch 'erisdev' into 1532
bsian03 Oct 19, 2024
0533eaf
add authorizingIntegrationOwners
retrouser955 Nov 10, 2024
d2e05fb
Merge branch 'dev' of https://github.com/retrouser955/eris into dev
retrouser955 Nov 10, 2024
1fa31d3
chore(lint) && integration_types_configuration
retrouser955 Nov 11, 2024
f22ad92
add install params and custom install url
retrouser955 Nov 11, 2024
49fbb92
Merge branch 'dev' into dev
retrouser955 Nov 30, 2024
391188a
chore(lint): dts
retrouser955 Dec 13, 2024
3cb938f
deprecate `<Message>.interaction`
retrouser955 Dec 13, 2024
545fb50
feat(interaction metadata): Init types
retrouser955 Dec 13, 2024
dce393c
chore(lint)
retrouser955 Dec 13, 2024
3bb0f7c
update types
retrouser955 Dec 13, 2024
155f669
updated message interaction metadata
retrouser955 Dec 17, 2024
9f47191
docs: add jsdoc
retrouser955 Dec 18, 2024
aefd654
docs(jsdoc): Complete types
retrouser955 Dec 18, 2024
8fd9f8a
chore: lint
retrouser955 Dec 18, 2024
498393d
fix(docs): readd user to interactionMetadata
retrouser955 Dec 18, 2024
239bf73
fix(interactionMetadata): parse model submit correctly
retrouser955 Dec 19, 2024
a7c1777
fix(interactionMetadata): Parse modelsubmit correct
retrouser955 Dec 19, 2024
1a10aeb
Merge branch 'dev' into dev
bsian03 Sep 27, 2025
092107e
copilot fixes
bsian03 Sep 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/userCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const Eris = require("eris");

const Constants = Eris.Constants;

const bot = new Eris("Bot token", {
intents: []
});

bot.on("ready", () => {
console.log("connected!")
bot.createCommand({
type: Constants.ApplicationCommandTypes.CHAT_INPUT,
name: "ping",
description: "Reply with pong",
options: [],
/* The following 2 lines set the state of the application command as both user installable and guild installable */
contexts: [Constants.ApplicationCommandContextType.GUILD, Constants.ApplicationCommandContextType.BOT_DM, Constants.ApplicationCommandContextType.PRIVATE],
integration_types: [Constants.ApplicationCommandIntegrationTypes.GUILD_INSTALL, Constants.ApplicationCommandIntegrationTypes.USER_INSTALL]
})
})

bot.on("interactionCreate", (interaction) => {
if(interaction instanceof Eris.CommandInteraction) {
if(interaction.data.name === "ping") {
let where = ""
/**
* <CommandInteraction>.context includes information of where the command was executed.
* if <CommandInteraction>.context matches ...
* Constants.ApplicationCommandContextType.GUILD it means it is executed from a server
* Constants.ApplicationCommandContextType.BOT_DM it means it is executed from the bot's DM
* Constants.ApplicationCommandContextType.PRIVATE it means it is executed as a user installable
*
* Incase of BOT_DM and PRIVATE, the CommandInteraction will lose all its guild related properties such as the guild information and member data
*/
const context = interaction.context

if(context === Constants.ApplicationCommandContextType.GUILD) {
where = "as a server interaction."
} else if(context === Constants.ApplicationCommandContextType.BOT_DM) {
where = "as a bot DM interaction."
} else if(context === Constants.ApplicationCommandContextType.PRIVATE) {
where = "as a private interaction (user installable)."
} else {
where = "as a server interaction."
}

interaction.createMessage(`🏓 pong ${where}`)
}
}
})

bot.connect()
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ declare namespace Eris {
description: U extends Constants["ApplicationCommandTypes"]["CHAT_INPUT"] ? string : "" | void;
name: string;
type?: U;
contexts: Number[];
integration_types: Number[];
}
/** Generic T is `true` if editing Guild scoped commands, and `false` if not */
interface ApplicationCommandBulkEditOptions<T extends boolean, U = ApplicationCommandTypes> extends ApplicationCommandCreateOptions<T, U> {
Expand Down Expand Up @@ -1897,6 +1899,15 @@ declare namespace Eris {
interface Constants {
GATEWAY_VERSION: 9;
REST_VERSION: 9;
ApplicationCommandContextType: {
GUILD: 0,
BOT_DM: 1,
PRIVATE: 2
}
ApplicationCommandIntegrationTypes: {
GUILD_INSTALL: 0,
USER_INSTALL: 1
}
ActivityFlags: {
INSTANCE: 1;
JOIN: 2;
Expand Down Expand Up @@ -3514,6 +3525,7 @@ declare namespace Eris {
member: T extends AnyGuildChannel ? Member : undefined;
type: Constants["InteractionTypes"]["APPLICATION_COMMAND"];
user: T extends AnyGuildChannel ? undefined : User;
context?: number
acknowledge(flags?: number): Promise<void>;
createFollowup(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise<Message>;
createMessage(content: string | InteractionContent, file?: FileContent | FileContent[]): Promise<void>;
Expand Down
2 changes: 2 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ class Client extends EventEmitter {
* @arg {Boolean} [command.nsfw=false] Whether the command is age-restricted
* @arg {Array<Object>} [command.options] The application command [options](https://discord.dev/interactions/application-commands#application-command-object-application-command-option-structure)
* @arg {Number} [command.type=1] The command type, either `1` for `CHAT_INPUT`, `2` for `USER` or `3` for `MESSAGE`
* @arg {Number[]?} [command.contexts] Configure if the command is a user-installable GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types)
* @arg {Number[]?} [command.integration_types] Configure the installation state of the slash command GUILD_INSTALL=0 USER_INSTALL=1 [more info](https://discord.com/developers/docs/resources/application#application-object-application-integration-types)
* @returns {Promise<ApplicationCommand>} Resolves with the created application command
*/
createCommand(command) {
Expand Down
11 changes: 11 additions & 0 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ module.exports.ActivityFlags = {
EMBEDDED: 1 << 8
};

module.exports.ApplicationCommandContextType = {
GUILD: 0,
BOT_DM: 1,
PRIVATE: 2
}

module.exports.ApplicationCommandIntegrationTypes = {
GUILD_INSTALL: 0,
USER_INSTALL: 1
}

module.exports.ActivityTypes = {
GAME: 0,
STREAMING: 1,
Expand Down
4 changes: 4 additions & 0 deletions lib/structures/ApplicationCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Permission = require("./Permission");
* @prop {Array<Object>?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command
* @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
* @prop {String} version The ID of the version of this command
* @prop {Number[]?} contexts The context of the command (if the command is a user-installable or a guild-installable)
*/
class ApplicationCommand extends Base {
constructor(data, client) {
Expand Down Expand Up @@ -56,6 +57,9 @@ class ApplicationCommand extends Base {
if(data.nsfw !== undefined) {
this.nsfw = data.nsfw;
}
if(data.contexts !== undefined) {
this.contexts = data.contexts
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {InteractionResponseTypes} = require("../Constants");
* @prop {String?} guildID The ID of the guild in which the interaction was created
* @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
* @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
* @prop {Number} context Where the interaction is sent from GUILD=0 BOT_DM=1 PRIVATE=2 [more info](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types)
*/
class CommandInteraction extends Interaction {
constructor(data, client) {
Expand All @@ -45,6 +46,8 @@ class CommandInteraction extends Interaction {

this.data = JSON.parse(JSON.stringify(data.data));

this.context = data.context

if(data.data.resolved !== undefined) {
//Users
if(data.data.resolved.users !== undefined) {
Expand Down Expand Up @@ -105,7 +108,7 @@ class CommandInteraction extends Interaction {
this.member = this.channel.guild.members.update(data.member, this.channel.guild);
} else {
const guild = this._client.guilds.get(data.guild_id);
this.member = guild.members.update(data.member, guild);
this.member = guild?.members?.update(data.member, guild);
}
}

Expand Down