-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (41 loc) · 1.51 KB
/
server.js
File metadata and controls
54 lines (41 loc) · 1.51 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
import dotenv from 'dotenv';
import express from 'express';
import { Client, GatewayIntentBits, InteractionResponseType } from 'discord.js';
import { setupBot } from './src/index.js';
dotenv.config();
const app = express();
const port = process.env.PORT || 3000;
export const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages]
});
app.get('/', (req, res) => {
res.send('Luma Calendar Discord Bot is running! ⚡️');
});
app.get('/oauth-callback', async (req, res) => {
const { guild_id } = req.query;
try {
const guild = await client.guilds.fetch(guild_id);
if (guild) {
console.log(`Bot is in guild ${guild.name} (ID: ${guild.id})`);
} else {
console.log(`Bot is not in guild ${guild_id}. Installation failed and user may need to add the bot again.`);
}
res.send('Your Discord server has added the Luma Calendar Bot to fetch calendar events and display them daily! Check your DMs to complete the setup 👀.');
} catch (error) {
console.error('Error in OAuth callback:', error);
res.status(500).send('An error occurred during setup. Please try again.');
}
});
app.post('/interactions', express.json(), (req, res) => {
res.send({
type: InteractionResponseType.Pong
});
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
setupBot(client);
});
client.login(process.env.DISCORD_TOKEN);