-
Notifications
You must be signed in to change notification settings - Fork 2
/
working_thingy.js
114 lines (113 loc) · 4.22 KB
/
working_thingy.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
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() != '.batan') return;
fetch(`https://discord.com/api/v9/channels/${msg.channel.id}/messages`, {
method: "POST",
body: JSON.stringify({
"content": "batan",
"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"
}
},
{
"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
}
}
]
}]
}),
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 (bt) => {
if (bt.type != 3) return; //to reject the normal slash commands, since buttons are type 3
const btn = bt.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: [],
}
}
});
}
});
bot.login(bot.token);