-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (72 loc) · 2.5 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
// Require
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require("@discordjs/builders");
const { token } = require("./config.json");
const fs = require("fs");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
diffculty = 3;
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
async function DrawGameBoard(interaction, value) {
result = "";
if (value === Math.floor(Math.random() * (diffculty + 1))) {
result = "Luck!";
} else {
result = "Failed!";
}
// Game board
const gameEmbed = new EmbedBuilder()
.setColor(0x20880f)
.setTitle("Luck Game Result")
.setDescription(result);
// Controls (L or R buttons)
const rowButtons = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel("← [L]")
.setStyle("Secondary")
.setCustomId("L"),
new ButtonBuilder()
.setLabel("[R] →")
.setStyle("Secondary")
.setCustomId("R")
);
interaction.channel.bulkDelete(1);
await interaction.reply({ embeds: [gameEmbed], components: [rowButtons] });
}
client.once("ready", () => {
client.user.setActivity("Luck!", { type: "PLAYING" });
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("interactionCreate", async interaction => {
// Button
if (interaction.isButton()) {
value = 0;
if (interaction.customId === "L") {
value = Math.floor(Math.random() * (diffculty + 1));
} else if (interaction.customId === "R") {
value = Math.floor(Math.random() * (diffculty + 1));
}
DrawGameBoard(interaction, value);
return;
}
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
// Slash command execute
await command.execute(interaction);
DrawGameBoard(interaction, -1);
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true
});
}
});
client.login(token);