-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (57 loc) · 2.41 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
const { Client, Events, GatewayIntentBits } = require('discord.js');
const dotenv = require('dotenv');
const express = require('express');
const axios = require('axios');
const prompt=require("prompt-sync")({sigint:true});
dotenv.config();
const token = process.env.DISCORD_TOKEN;
const app = express();
const PORT = 3000;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
console.log(token);
async function scheduleEvent(name, startTime, endTime, description, imageUrl) {
try {
const guild = await client.guilds.fetch(process.env.GUILD_ID);
const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
const imageBuffer = Buffer.from(response.data, 'binary');
const imageBase64 = `data:image/jpeg;base64,${imageBuffer.toString('base64')}`;
const scheduledEvent = await guild.scheduledEvents.create({
name: name,
privacyLevel: 2,
scheduledStartTime: startTime,
scheduledEndTime: endTime,
entityType: 3,
entityMetadata: { location: "TEST"},
description: description,
image: imageBase64
});
const channel = await client.channels.fetch(process.env.CHANNEL_ID);
await channel.send(`@everyone 🎉 A new event "${scheduledEvent.name}" has been scheduled! It will start on <t:${Math.floor(startTime.getTime() / 1000)}:F>.`);
console.log("Event successfully scheduled!");
} catch (error) {
console.error("Error creating scheduled event: " + error);
}
}
app.get("/create-event", (req, res) => {
let name = prompt("Name of event: ");
let description = prompt("Provide description of event: ");
const startTime = new Date('2024-08-26T15:00:00Z');
const endTime = new Date('2024-08-26T16:00:00Z');
// test image
const imageUrl = "https://th.bing.com/th/id/R.b278428a21699d82d8bda5ecff4d3fba?rik=VCLWUCs8MAqrJw&pid=ImgRaw&r=0";
scheduleEvent(name, startTime, endTime, description, imageUrl);
res.send("Event creation process started. Refer to terminal for instructions!");
})
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
})
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
client.login(token);