-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
106 lines (91 loc) · 2.81 KB
/
Copy pathindex.js
File metadata and controls
106 lines (91 loc) · 2.81 KB
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
const {
readFile
} = require('fs/promises');
const path = require('path');
require('dotenv').config();
const {
Client,
GatewayIntentBits,
REST,
Routes,
SlashCommandBuilder,
TextDisplayBuilder,
ContainerBuilder,
MessageFlags,
ButtonBuilder,
SectionBuilder,
ButtonStyle,
SeparatorSpacingSize,
FileBuilder,
AttachmentBuilder
} = require('discord.js');
const {
TOKEN,
CLIENT_ID
} = process.env;
const client = new Client({
intents: [Object.keys(GatewayIntentBits)],
});
const rest = new REST({
version: '10'
}).setToken(TOKEN);
const commands = [
new SlashCommandBuilder()
.setName('test')
.setDescription('Testing command.')
.toJSON(),
];
async function init() {
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands
});
console.log('Commands registered.');
}
client.once('ready', () => {
console.log(`Logged in as ${client.user.username}!`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName !== 'test') return;
const FileContent = path.join(__dirname, 'NiNJA.xex');
const Path = await readFile(FileContent, 'utf8');
const component = new ContainerBuilder();
const s1 = new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder().setContent('Hello world!\nThis is a test message.')
)
.setButtonAccessory(
new ButtonBuilder()
.setLabel('Click me!')
.setStyle(ButtonStyle.Secondary)
.setCustomId('test1')
);
const s2 = new SectionBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder().setContent('Hello world! 1\nThis is a test message. 2')
)
.setButtonAccessory(
new ButtonBuilder()
.setLabel('Click me!')
.setStyle(ButtonStyle.Danger)
.setCustomId('test2')
);
const hintText = new TextDisplayBuilder()
.setContent("-# small little hello world!\n");
component.addSectionComponents(s1);
component.addSeparatorComponents(s => s.setSpacing(SeparatorSpacingSize.Small));
component.addSectionComponents(s2);
component.addSeparatorComponents(s => s.setSpacing(SeparatorSpacingSize.Small));
component.addTextDisplayComponents(hintText);
component.addFileComponents(
new FileBuilder().setURL('attachment://NiNJA.xex')
);
await interaction.reply({
components: [component],
files: [new AttachmentBuilder(Buffer.from(Path), {
name: 'NiNJA.xex',
})],
flags: MessageFlags.IsComponentsV2,
});
});
init().then(() => client.login(TOKEN));