Skip to content

Commit

Permalink
Support Interactions (abalabahaha#1280)
Browse files Browse the repository at this point in the history
Co-Authored-By: Donovan Daniels <[email protected]>
Co-Authored-By: Reinhardt <[email protected]>
Co-authored-by: DetachHead <[email protected]>
Co-authored-by: Loliticos <[email protected]>
Co-Authored-By: Gwee&Kwee <[email protected]>
Co-Authored-By: coolcalcacol <[email protected]>
Co-authored-by: Lava <[email protected]>
Co-authored-by: Avocado <[email protected]>
Co-authored-by: bsian03 <[email protected]>
Co-authored-by: abalabahaha <[email protected]>
  • Loading branch information
11 people authored Oct 31, 2021
1 parent da84b35 commit a9c4934
Show file tree
Hide file tree
Showing 18 changed files with 2,529 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.vscode
docgen
docs
node_modules
Expand Down
6 changes: 6 additions & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default function(token, options) {
}

export const {
AutocompleteInteraction,
Base,
Bucket,
Call,
Expand All @@ -14,6 +15,8 @@ export const {
Collection,
Command,
CommandClient,
CommandInteraction,
ComponentInteraction,
Constants,
DiscordHTTPError,
DiscordRESTError,
Expand All @@ -24,12 +27,14 @@ export const {
GuildIntegration,
GuildPreview,
GuildTemplate,
Interaction,
Invite,
Member,
Message,
NewsChannel,
Permission,
PermissionOverwrite,
PingInteraction,
PrivateChannel,
Relationship,
RequestHandler,
Expand All @@ -40,6 +45,7 @@ export const {
StoreChannel,
TextChannel,
UnavailableGuild,
UnknownInteraction,
User,
VERSION,
VoiceChannel,
Expand Down
101 changes: 101 additions & 0 deletions examples/applicationCommands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const Eris = require("eris");

const Constants = Eris.Constants;

// Replace TOKEN with your bot account's token
const bot = new Eris("BOT TOKEN", {
intents: [] //No intents are needed for interactions, but you still need to specify either an empty array or 0
});

bot.on("ready", async () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"

//Note: You should use guild commands to test, as they update instantly. Global commands can take up to an hour to update.

const commands = await bot.getCommands();

if(!commands.length) {
bot.createCommand({
name: "test_chat_input",
description: "Test command to show how to make commands",
options: [ //An array of Chat Input options https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
{
"name": "animal", //The name of the option
"description": "The type of animal",
"type": Constants.ApplicationCommandOptionTypes.STRING, //This is the type of string, see the types here https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type
"required": true,
"choices": [ //The possible choices for the options
{
"name": "Dog",
"value": "animal_dog"
},
{
"name": "Cat",
"value": "animal_cat"
},
{
"name": "Penguin",
"value": "animal_penguin"
}
]
},
{
"name": "only_smol",
"description": "Whether to show only baby animals",
"type": Constants.ApplicationCommandOptionTypes.BOOLEAN,
"required": false
}
],
type: Constants.ApplicationCommandTypes.CHAT_INPUT //Not required for Chat input type, but recommended
}); //Create a chat input command

bot.createCommand({
name: "Test User Menu",
type: Constants.ApplicationCommandTypes.USER
}); //Create a user context menu

bot.createCommand({
name: "Test Message Menu",
type: Constants.ApplicationCommandTypes.MESSAGE
}); //Create a message context menu

bot.createCommand({
name: "test_edit_command",
description: "Test command to show off how to edit commands",
type: Constants.ApplicationCommandTypes.CHAT_INPUT //Not required for Chat input type, but recommended
}); //Create a chat input command

bot.createCommand({
name: "test_delete_command",
description: "Test command to show off how to delete commands",
type: Constants.ApplicationCommandTypes.CHAT_INPUT //Not required for Chat input type, but recommended
}); //Create a chat input command

//In practice, you should use bulkEditCommands if you need to create multiple commands
}
});

bot.on("error", (err) => {
console.error(err); // or your preferred logger
});

bot.on("interactionCreate", (interaction) => {
if(interaction instanceof Eris.CommandInteraction) {
switch(interaction.data.name) {
case "test_edit_command":
interaction.createMessage("interaction recieved");
return bot.editCommand(interaction.data.id, {
name: "edited_test_command",
description: "Test command that was edited by running test_edit_command"
});
case "test_delete_command":
interaction.createMessage("interaction recieved");
return bot.deleteCommand(interaction.data.id);
default: {
return interaction.createMessage("interaction recieved");
}
}
}
});

bot.connect(); // Get the bot to connect to Discord
82 changes: 82 additions & 0 deletions examples/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const Eris = require("eris");

const Constants = Eris.Constants;

// Replace TOKEN with your bot account's token
const bot = new Eris("BOT TOKEN", {
intents: ["guildMessages"]
});

bot.on("ready", async () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"
});

bot.on("error", (err) => {
console.error(err); // or your preferred logger
});

bot.on("messageCreate", (msg) => { // When a message is created
if(msg.content === "!button") { // If the message content is "!button"
bot.createMessage(msg.channel.id, {
content: "Button Example",
components: [
{
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 1 select menu per action row
components: [
{
type: Constants.ComponentTypes.BUTTON, // https://discord.com/developers/docs/interactions/message-components#buttons
style: Constants.ButtonStyles.PRIMARY, // This is the style of the button https://discord.com/developers/docs/interactions/message-components#button-object-button-styles
custom_id: "click_one",
label: "Click me!",
disabled: false // Whether or not the button is disabled, is false by default
}
]
}
]
});
// Send a message in the same channel with a Button
} else if(msg.content === "!select") { // Otherwise, if the message is "!select"
bot.createMessage(msg.channel.id, {
content: "Select Menu Example",
components: [
{
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 5 buttons per action row
components: [
{
type: Constants.ComponentTypes.SELECT_MENU, // https://discord.com/developers/docs/interactions/message-components#select-menus
custom_id: "select_one",
placeholder: "Select an option",
options: [ // The options to select from https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
{
label: "Option 1",
value: "option_1",
description: "[Insert description here]"
},
{
label: "Option 2",
value: "option_2",
description: "This is only here to show off picking one"
}
],
min_values: 1,
max_values: 1,
disabled: false // Whether or not the select menu is disabled, is false by default
}
]
}
]
});
// Send a message in the same channel with a Select Menu
}
});

bot.on("interactionCreate", (interaction) => {
if(interaction instanceof Eris.ComponentInteraction) {
return interaction.createMessage({
content: "Interaction Recieved",
flags: 64
});
}
});

bot.connect(); // Get the bot to connect to Discord
Loading

0 comments on commit a9c4934

Please sign in to comment.