-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
112 lines (90 loc) · 2.7 KB
/
bot.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
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
/*reThread by dnji. Made using discord.js*/
require("dotenv").config();
const { Client, IntentsBitField, ThreadChannel } = require('discord.js');
const client = new Client({ intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
const token = process.env.BOT_TOKEN;
const guildId = process.env.GUILD_ID;
var active = true;
const initClient = async () => {
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
});
await client.login(token);
return true;
};
// Method to fetch all channels in a guild
const fetchAllChannels = async () => {
console.log("running faC...")
const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.error(`Guild with ID ${guildId} not found`);
return;
}
const channels = guild.channels.cache;
channels.forEach(async (channel) => {
// Check if the channel is a thread
if (channel.isThread()) {
// Autojoin the thread
try {
await channel.join();
} catch (error) {
}
channel.setArchived(false)
if(channel.archived = true) {
channel.send({
content: "refresh",
flags: [ 4096 ]
})
.then(msg => {
setTimeout(() => msg.delete(), 10)
})
}
}
});
console.log("faC finished...")
};
async function main() {
const status = await initClient();
console.log(status);
await new Promise(resolve => setTimeout(resolve, 500));
var runCount = 0;
while(true) {
runCount = runCount + 1;
console.log(runCount);
if(active) {
await fetchAllChannels();
await new Promise(resolve => setTimeout(resolve, 86000000));
console.log("end of wait");
}
await new Promise(resolve => setTimeout(resolve, 400000));
console.log("reloading...")
}
}
main();
client.on("interactionCreate", (i) => {
if(!i.isChatInputCommand()) return;
if(i.commandName == "hey")
i.reply("hey");
if(i.commandName == "refresh") {
fetchAllChannels()
i.reply("reloaded!")
}
if(i.commandName == "on") {
active = true
i.reply("auto refresh is now on!")
}
if(i.commandName == "off") {
active = false
i.reply("auto refresh is now off!")
}
if(i.commandName == "status") {
if(active) i.reply("auto refresh is on");
else i.reply("auto refresh is off");
}
})