-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
131 lines (131 loc) · 5.33 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const Client = require('discord.js');
const fetch = require('node-fetch');
const bot = new Client({
allowedMentions: { parse: [] },
intents: new Intents(Intents.ALL)
});
bot.prefix = ".";
bot.token = token;
bot.on('ready', async () => {
bot.application.commands.create({
name: "button",
description: "example for button"
});
const guild = bot.guilds.cache.get("the id");
await guild.commands.create({
name: "button-g",
description: "example for button, but guild command"
});
bot.user.setActivity("stuff");
console.log('online');
});
bot.on('message', async (msg) => {
if (msg.author.bot) return;
if (msg.content.toLowerCase() != '.drop-the-beat') return;
fetch(`https://discord.com/api/v9/channels/${msg.channel.id}/messages`, {
method: "POST",
body: JSON.stringify({
"content": "batan",
"components": [{
"type": 1,
"components": [
{
"type": 1, "components":[
{
type: 3,
custom_id: "help", //this will be the main id of the whole dropdown
label: "test",
options: [
{
label: "help",
value: "home", //this will be the id of a single value in the dropdowns
default: true, //if you want one value to be seen as default
description: "get the main help commands, like, category wise",
emoji: { id: "781553329452220477"}
},
{
label: "canva",
value: "canva",
default: false,
description: "get all the image commands",
emoji: { id: "816698525219815464" }
},
{
label: "emoji",
value: "emoji",
default: false,
description: "get the emoji commands",
emoji: { id: "821670793368043540"}
}
],
placeholder: "HELP!", //placeholder will be the default display if you have default turned off for all the values
min_values: 1, //minimum number of choices one can take off dropdowns
max_values: 1, //maximum number of choices one can take off dropdowns
},
],
}]
]
}]
}),
headers: {
"Authorization": `Bot ${bot.token}`,
"Content-Type": "application/json"
}
})
});
bot.on('interaction', async (interaction) => {
if (interaction.commandName != "button") return;
bot.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
/*flags: 64*/ //for ephemeral
data: {
content: "buttons test",
embeds: [],
components: [{
"type": 1, "components": [
{
"type": 2, //buttons
"label": "batan", //the thing you want to display
"style": 4, //red
"custom_id": "the_id_you_want", //the id
"emoji": { //if you want emoji
"name": "the emoji name",
"id": "the emoji is"
} //YES I COPY PASTED THIS FROM ABOVE
},
{
"type": 2, //buttons
"label": "link", //the thing you want to display
"style": 5, //url button
"url": "the_url",
"emoji": { //if you want emoji
"name": "the emoji name",
"id": "the emoji is" //don't fill the id if you want ascii
}
}
]
}]
}
}
})
});
bot.on('INTERACTION_CREATE', async (int) => {
if (int.data.component_type == 2) { //buttons
const btn = int.data.custom_id;
if (btn == "the_id_you_want") {
bot.api.interactions(bt.id, bt.token).callback.post({
data: {
type: 7, //this will edit the original interaction, change it to type 4 if you want to send a new message and set it to flags: 64 if you only want it to be seen by the user
data: {
content: "the action or the reply or something",
embeds: [],
}
}
});
}
} else if(bt.data.component_type == 3){
//same way replying to normal buttons
}
});
bot.login(bot.token);