-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
124 lines (106 loc) · 6.53 KB
/
Copy pathindex.js
File metadata and controls
124 lines (106 loc) · 6.53 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
const { Client, GatewayIntentBits, ActivityType, Collection, ChannelType } = require('discord.js');
const configs = require('./config.json');
require('colors');
const voiceData = new Collection();
const client = new Client({
intents: [
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent
],
presence: {
activities: [{name: `Voice Channels`, type: ActivityType.Watching}],
status: "idle" // "online", "dnd", "idle"
}
});
// Anti Crash
process.on('unhandledRejection', (err, cause) => {
if(err.code == 10008 || err.code == 10062) return;
console.log(`[Uncaught Exception]: ${err}`.bold.brightGreen);
console.log(cause)
});
process.on('uncaughtException', err => {
console.log(`[Uncaught Exception] ${err.message}`.bold.brightGreen);
console.log(err);
});
// Event Code: When voiceData of any Member is updated
client.on("voiceStateUpdate", async (oldState, newState) => {
const member = oldState.member;
const guild = oldState.guild;
// implement mongodb here for Multi guild bot, to fetch variables from database rather than JSON file
const channelid = configs.channelId;
const userlimit = configs.userLimit;
const nameFormat = configs.nameFormat;
const categoryid = configs.categoryId;
const bitrate = configs.bitrate;
const memberPerms = configs.memberPerms;
const everyonePerms = configs.everyonePerms;
// ---------------------------------------------
if(!channelid || channelid.length == 0) return console.log(`[J2C Bot] Channel ID is missing in config.json File or unable to get it from Database.`.bold.brightRed);
const j2c = guild.channels.cache.get(channelid);
if(!j2c) return console.log(`[J2C Bot] J2C Channel ID is not Valid.`.bold.brightRed);
// When user is reconnects due to network issues
if(newState.channel?.id == oldState.channel?.id) return;
// Member joins J2C Channel
if(newState.channel?.id == channelid) {
// If user shifts from existing J2C VC to J2C Channel
const data = voiceData.get(member.id);
if(data && data.channel == oldState.channel?.id) return await member.voice.setChannel(data.channel).catch(e => console.log(`[J2C Bot] Missing Move member permission.`.red));
// Creating a new VC for the user
let vcId = await guild.channels.create({
name: `${nameFormat} ${member.displayName}`,
type: ChannelType.GuildVoice,
parent: categoryid.length == 0 ? j2c.parentId : categoryid,
bitrate: bitrate,
permissionOverwrites: [
{
id: member.id,
allow: [memberPerms],
},
{
id: guild.id,
allow: [everyonePerms],
},
],
userLimit: userlimit
}).then(c => c.id, e => console.log(`[J2C Bot] Something went wrong while creating a new VC for ${member.displayName}: ${e}`.red));
if(!vcId) return;
// Data to store in collection: Modify the object according to your needs.
voiceData.set(member.id, {channel: vcId, time: Date.now()});
return await member.voice.setChannel(vcId).catch(e => console.log(`[J2C Bot] Missing Move member permission.`.red));
}
// Member leaves J2C VC
const data = voiceData.get(member.id);
if(!data) return;
if(oldState.channel?.id != data.channel) return;
const remainingMembers = oldState.channel.members.filter(m => !m.user.bot).map((m) => m.id);
if(remainingMembers.length == 0) {
oldState.channel.delete().catch(e => console.log(`[J2C Bot] Missing Channel Delete permission.`.red));
return voiceData.delete(member.id);
} else {
let otherVcMember = await guild.members.fetch(remainingMembers[0]).catch(e => null);
if(!otherVcMember) {
oldState.channel.delete().catch(e => console.log(`[J2C Bot] Missing Channel Delete permission.`.red));
return voiceData.delete(member.id);
}
oldState.channel.setName(`${nameFormat} ${otherVcMember.displayName}`).catch(e => null);
voiceData.set(otherVcMember.id, {channel: oldState.channel.id, time: Date.now()});
voiceData.delete(member.id);
}
});
client.on('ready', () => {
console.log(`
░░░░░██╗░█████╗░██╗███╗░░██╗░░░░░░████████╗░█████╗░░░░░░░░█████╗░██████╗░███████╗░█████╗░████████╗███████╗
░░░░░██║██╔══██╗██║████╗░██║░░░░░░╚══██╔══╝██╔══██╗░░░░░░██╔══██╗██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
░░░░░██║██║░░██║██║██╔██╗██║█████╗░░░██║░░░██║░░██║█████╗██║░░╚═╝██████╔╝█████╗░░███████║░░░██║░░░█████╗░░
██╗░░██║██║░░██║██║██║╚████║╚════╝░░░██║░░░██║░░██║╚════╝██║░░██╗██╔══██╗██╔══╝░░██╔══██║░░░██║░░░██╔══╝░░
╚█████╔╝╚█████╔╝██║██║░╚███║░░░░░░░░░██║░░░╚█████╔╝░░░░░░╚█████╔╝██║░░██║███████╗██║░░██║░░░██║░░░███████╗
░╚════╝░░╚════╝░╚═╝╚═╝░░╚══╝░░░░░░░░░╚═╝░░░░╚════╝░░░░░░░░╚════╝░╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚══════╝
`.blue.bold);
console.log("----------------------------------------".blue);
console.log(`[Djs v14: READY] ${client.user.tag} is up and ready to go.`.bold)
console.log("----------------------------------------".white);
});
client.login(configs.token);