forked from abalabahaha/eris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Interactions (abalabahaha#1280)
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
1 parent
da84b35
commit a9c4934
Showing
18 changed files
with
2,529 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
.vscode | ||
docgen | ||
docs | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.