-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
79 lines (65 loc) · 2.13 KB
/
Copy pathapp.js
File metadata and controls
79 lines (65 loc) · 2.13 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
import {
Client,
GatewayIntentBits,
Events,
Collection,
Partials
} from "discord.js";
import "dotenv/config";
import { Constants } from './constants.js'
import echo from "./commands/echo.js";
import ping from "./commands/ping.js";
import roll from "./commands/roll.js";
import routes from './routes.js';
import express from 'express';
import bodyParser from 'body-parser';
// Create a new client instance
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
});
// When the client is ready, run this code (only once)
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
// Log in to Discord with your client's token
client.login(Constants.token);
client.commands = new Collection();
client.commands.set(roll.data.name, roll);
client.commands.set(echo.data.name, echo);
client.commands.set(ping.data.name, ping);
// commands
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
// handle emojis
client.on(Events.MessageReactionAdd, async (reaction, user) => {});
// handle emoji removes
client.on(Events.MessageReactionRemove, async (reaction, user) => {});
// express web server
const app = express();
// Add JSON body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use((req, res, next) => {
res.locals.client = client;
next();
});
// Add routes
routes(app);
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, '::', () => {
console.log(`Server is running on port ${PORT}.`);
});