This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (40 loc) · 1.55 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
require('dotenv').config()
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { Client, Intents } = require('discord.js');
const fs = require('fs');
const commands = [
new SlashCommandBuilder().setName('quote').setDescription('Answer with a quote from Marc Droin!'),
].map(command => command.toJSON());
const rest = new REST({ version: '9' }).setToken(process.env.TOKEN);
rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
const MASTERCLASS = fs.readFileSync('masterclass.md').toString().split("\n");
function getRandomQuote() {
const element = MASTERCLASS[Math.floor(Math.random() * MASTERCLASS.length)].slice(2)
return element
}
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'quote') {
const element = getRandomQuote();
await interaction.reply(element);
}
});
client.login(process.env.TOKEN);
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
app.get('/', (req, res) => {
res.send({ quote: getRandomQuote() })
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})