-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.js
More file actions
178 lines (141 loc) · 6.74 KB
/
bot.js
File metadata and controls
178 lines (141 loc) · 6.74 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
________.__ _____.___.___________
/ _____/| | _____ ____ ____ \__ | |\__ ___/
/ \ ___| | \__ \ _/ ___\/ __ \ / | | | |
\ \_\ \ |__/ __ \\ \__\ ___/ \____ | | |
\______ /____(____ /\___ >___ > / ______| |____|
\/ \/ \/ \/ \/
╔════════════════════════════════════════════════════════════════════════╗
║ ║
║ ## Created by GlaceYT! ║
║ ## Feel free to utilize any portion of the code ║
║ ## DISCORD : https://discord.com/invite/xQF9f9yUEM ║
║ ## YouTube : https://www.youtube.com/@GlaceYt ║
║ ║
╚════════════════════════════════════════════════════════════════════════╝
*/
const { Client, GatewayIntentBits, EmbedBuilder, TextChannel, Discord } = require("discord.js");
const config = require("./config.js");
const fs = require("fs");
const path = require('path');
const { printWatermark } = require('./util/pw');
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a) => {
return GatewayIntentBits[a];
}),
});
client.config = config;
fs.readdir("./events", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
client.commands = [];
fs.readdir(config.commandsDir, (err, files) => {
if (err) throw err;
files.forEach(async (f) => {
try {
if (f.endsWith(".js")) {
let props = require(`${config.commandsDir}/${f}`);
client.commands.push({
name: props.name,
description: props.description,
options: props.options,
});
}
} catch (err) {
console.log(err);
}
});
});
client.on('guildMemberAdd', async member => {
try {
const setupFilePath = path.join(__dirname, 'setup.json');
const setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf8'));
const guildId = member.guild.id;
const guildSetupData = setupData[guildId];
if (!guildSetupData || !guildSetupData.welcomeChannelId) {
console.error('Welcome channel data not found or invalid.');
return;
}
const welcomeChannelId = guildSetupData.welcomeChannelId;
console.log('Welcome channel ID:', welcomeChannelId);
const welcomeChannel = await client.channels.fetch(welcomeChannelId);
if (!welcomeChannel) {
console.error('Welcome channel not found.');
return;
}
console.log('Welcome channel type:', welcomeChannel.type);
const messageFilePath = path.join(__dirname, 'message.json');
const messageData = JSON.parse(fs.readFileSync(messageFilePath, 'utf8'));
if (!messageData) {
console.error('Message details not found in message.json');
return;
}
const processedMessageData = {
...messageData,
// REMOVE BELOW ATTRIBUTE IN ORDER TO LOAD MESSAGE.JSON INFO
thumbnail: member.guild.iconURL(),
authorName: member.displayName,
authorURL: member.user.displayAvatarURL(),
authorIcon: member.user.displayAvatarURL()
};
const { title, description, image, footer, color, footerURL, thumbnail, authorName, authorURL, authorIcon } = processedMessageData;
const welcomeMessage = `Hello ${member}!`;
const welcomeMessageDm = `💝 This message has been sent from **${member.guild.name}!**`;
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setImage(image)
.setColor(color)
.setTimestamp()
.setFooter({ text: footer, iconURL: footerURL })
.setThumbnail(thumbnail)
.setAuthor({ name: authorName, iconURL: authorIcon, url: authorURL });
await welcomeChannel.send({ content: welcomeMessage, embeds: [embed] });
//REMOVE BELOW LINE IF YOU DONT WANT DM MESSAGE
await member.send({ content: welcomeMessageDm, embeds: [embed] });
} catch (error) {
console.error('Error sending welcome message:', error);
}
});
if (config.TOKEN || process.env.TOKEN) {
client.login(config.TOKEN || process.env.TOKEN).catch((e) => {
console.log('TOKEN ERROR❌ - Turn On Intents or Reset New Token');
});
} else {
setTimeout(() => {
console.log('TOKEN ERROR❌ - Turn On Intents or Reset New Token');
}, 2000);
}
const express = require("express");
const app = express();
const port = 3000;
app.get('/', (req, res) => {
const imagePath = path.join(__dirname, 'index.html');
res.sendFile(imagePath);
});
app.listen(port, () => {
console.log(`🔗 Listening to RTX: http://localhost:${port}`);
});
printWatermark();
/*
________.__ _____.___.___________
/ _____/| | _____ ____ ____ \__ | |\__ ___/
/ \ ___| | \__ \ _/ ___\/ __ \ / | | | |
\ \_\ \ |__/ __ \\ \__\ ___/ \____ | | |
\______ /____(____ /\___ >___ > / ______| |____|
\/ \/ \/ \/ \/
╔════════════════════════════════════════════════════════════════════════╗
║ ║
║ ## Created by GlaceYT! ║
║ ## Feel free to utilize any portion of the code ║
║ ## DISCORD : https://discord.com/invite/xQF9f9yUEM ║
║ ## YouTube : https://www.youtube.com/@GlaceYt ║
║ ║
╚════════════════════════════════════════════════════════════════════════╝
*/