-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscordBot.js
More file actions
44 lines (37 loc) · 1.48 KB
/
DiscordBot.js
File metadata and controls
44 lines (37 loc) · 1.48 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
const { Client, GatewayIntentBits } = require('discord.js');
// Function to send a confirmation message to the general channel
async function sendConfirmationMessage(existingClient) {
try {
console.log('Sending door unlock confirmation message...');
// Find the general channel
const guilds = existingClient.guilds.cache;
for (const guild of guilds.values()) {
try {
// Fetch all channels in the guild
const channels = await guild.channels.fetch();
// Try to find a channel named "general"
const generalChannel = channels.find(
channel => channel.name.toLowerCase() === 'general' && channel.isTextBased()
);
if (generalChannel) {
// await generalChannel.send('Door has been unlocked successfully! ✅ BUILD something great today!');
console.log('Confirmation message sent successfully!');
}
} catch (fetchError) {
console.error(`Error fetching channels for guild ${guild.name}:`, fetchError);
}
}
} catch (error) {
console.error('Error sending confirmation message:', error);
}
}
// Function to start the bot and send a message
function startBot(token, existingClient = null) {
if (existingClient) {
// If an existing client is provided, use it
sendConfirmationMessage(existingClient);
} else {
console.log('This function is now deprecated. Please use the DiscordChannelListener instead.');
}
}
module.exports = { startBot };