Tobkubos commited on
Commit
fc6d61f
·
1 Parent(s): e4b505c
Files changed (1) hide show
  1. index.js +59 -4
index.js CHANGED
@@ -1,7 +1,15 @@
1
  import dotenv from "dotenv";
2
  dotenv.config();
3
 
4
- import { Client, GatewayIntentBits, Events } from "discord.js";
 
 
 
 
 
 
 
 
5
 
6
  const client = new Client({
7
  intents: [
@@ -11,8 +19,56 @@ const client = new Client({
11
  ],
12
  });
13
 
14
- client.once(Events.ClientReady, () => {
15
  console.log(`Bot ready: ${client.user.tag}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  });
17
 
18
  client.on(Events.MessageCreate, (message) => {
@@ -20,5 +76,4 @@ client.on(Events.MessageCreate, (message) => {
20
  console.log(`Message from ${message.author.tag}: ${message.content}`);
21
  });
22
 
23
- console.log("Wczytany token:", process.env.DISCORD_TOKEN);
24
- client.login(process.env.DISCORD_TOKEN);
 
1
  import dotenv from "dotenv";
2
  dotenv.config();
3
 
4
+ import {
5
+ Client,
6
+ GatewayIntentBits,
7
+ Events,
8
+ ModalBuilder,
9
+ TextInputBuilder,
10
+ TextInputStyle,
11
+ ActionRowBuilder
12
+ } from "discord.js";
13
 
14
  const client = new Client({
15
  intents: [
 
19
  ],
20
  });
21
 
22
+ client.once(Events.ClientReady, async () => {
23
  console.log(`Bot ready: ${client.user.tag}`);
24
+
25
+ try {
26
+ await client.application.commands.set([
27
+ {
28
+ name: "detect",
29
+ description: "Otwiera okienko do wklejenia linku lub tekstu",
30
+ },
31
+ ]);
32
+ console.log("Pomyślnie zarejestrowano komendę /detect");
33
+ } catch (error) {
34
+ console.error("Błąd podczas rejestracji komendy:", error);
35
+ }
36
+ });
37
+
38
+ client.on(Events.InteractionCreate, async (interaction) => {
39
+
40
+ if (interaction.isChatInputCommand()) {
41
+ if (interaction.commandName === "detect") {
42
+
43
+ const modal = new ModalBuilder()
44
+ .setCustomId("detectModal")
45
+ .setTitle("Detektor linków/tekstu");
46
+
47
+ const textInput = new TextInputBuilder()
48
+ .setCustomId("detectInput")
49
+ .setLabel("Wklej tutaj link lub tekst do przetworzenia:")
50
+ .setStyle(TextInputStyle.Paragraph)
51
+ .setPlaceholder("Wklej zawartość...")
52
+ .setRequired(true);
53
+ const actionRow = new ActionRowBuilder().addComponents(textInput);
54
+ modal.addComponents(actionRow);
55
+
56
+ await interaction.showModal(modal);
57
+ }
58
+ }
59
+
60
+ if (interaction.isModalSubmit()) {
61
+ if (interaction.customId === "detectModal") {
62
+ const userContent = interaction.fields.getTextInputValue("detectInput");
63
+
64
+ await interaction.reply({
65
+ content: `ziemniak`,
66
+ ephemeral: true,
67
+ });
68
+
69
+ console.log(`Użytkownik wkleił: ${userContent}`);
70
+ }
71
+ }
72
  });
73
 
74
  client.on(Events.MessageCreate, (message) => {
 
76
  console.log(`Message from ${message.author.tag}: ${message.content}`);
77
  });
78
 
79
+ client.login(process.env.DISCORD_TOKEN);