-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (45 loc) · 1.34 KB
/
app.js
File metadata and controls
59 lines (45 loc) · 1.34 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
import 'dotenv/config';
import { Client, GatewayIntentBits } from 'discord.js';
import * as fs from 'fs';
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
// Chest
const responses = JSON.parse(fs.readFileSync("chestresponses.json"));
let responsesTotalWeight = 0;
for(const response of responses) {
responsesTotalWeight+=response.weight;
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async interaction => {
if (interaction.isChatInputCommand()) {
if (interaction.commandName === 'chest') {
await chest(interaction);
}
if (interaction.commandName === 'think') {
await think(interaction);
}
}
});
async function chest(interaction) {
await interaction.reply('Opening chest...');
await sleep(1000);
let selectedWeight = Math.random() * responsesTotalWeight;
let selectedResponse;
for(const response of responses) {
selectedWeight -= response.weight;
if(selectedWeight < 0) {
selectedResponse = response;
break;
}
}
await interaction.channel.send('You found ' + selectedResponse.item + '!');
}
// Think
async function think(interaction) {
return interaction.deferReply();
}
client.login(process.env.DISCORD_TOKEN);