forked from projectdysnomia/dysnomia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
components.js
84 lines (77 loc) · 3.59 KB
/
components.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const Dysnomia = require("@projectdysnomia/dysnomia");
const Constants = Dysnomia.Constants;
// Replace TOKEN with your bot account's token
const bot = new Dysnomia.Client("BOT TOKEN", {
gateway: {
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.STRING_SELECT, // 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 Dysnomia.ComponentInteraction) {
return interaction.createMessage({
content: "Interaction Received",
flags: 64
});
}
});
bot.connect(); // Get the bot to connect to Discord