-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
174 lines (146 loc) · 6.37 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
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
const { Client } = require('discord.js-selfbot-v13');
const { joinVoiceChannel } = require('@discordjs/voice');
const { TOKEN, PREFIX } = require('./config.json');
const client = new Client();
const AdminsUsers = ["910544911131115551", "851696808437743616", "783493253034541136" ]; // admins who can controle the bot
const PingCommand = `${PREFIX}ping`; // ping command
const AfkCommand = `${PREFIX}afk`; // afk command
const FollowCommand = `${PREFIX}follow`; // follow command
const SendDmcmmand = `${PREFIX}sendm` // sendm command
const PermCommand = `${PREFIX}check` // check command
let connection = null;
let follower = null;
client.on('ready', () => {
console.log(`Client logged in as ${client.user.username}`);
});
client.on('voiceStateUpdate', (oldstats, newstats) => {
if (follower) {
if (newstats.id == follower && oldstats.channelId != newstats.channelId) {
connection = joinVoiceChannel({
channelId: newstats.channelId,
guildId: newstats.guild.id,
adapterCreator: newstats.guild.voiceAdapterCreator,
selfDeaf: false, // Ensure the bot is not deafened
selfMute: false, // Ensure the bot is not muted
});
}
}
})
client.on('messageCreate', async (msg) => {
if (CheckUser(msg.author.id) && msg.content.startsWith(PREFIX)) {
//======================================================================================
// Get user roles
//======================================================================================
if (msg.content.startsWith(PermCommand)) {
const userId = msg.content.split(' ')[1];
if (!userId) {
return msg.reply("Please provide a user ID.");
}
try {
const permissions = await checkPermissionsAcrossGuilds(userId);
if (permissions.length === 0) {
msg.reply(`User ${userId} has no admin or manager permissions in any guild.`);
} else {
const reply = permissions.map(({ guildName, roles }) =>
`Guild: ${guildName}\nRoles: ${roles.join(', ')}`
).join('\n\n');
msg.reply(`User ${userId} has admin or manager permissions in the following guild(s):\n\n${reply}`);
}
} catch (err) {
console.error(err);
msg.reply("An error occurred while checking permissions.");
}
}
//======================================================================================
// Send dm to user ex +sendm [userid] [message]
//======================================================================================
if (msg.content.toLocaleLowerCase().startsWith(SendDmcmmand)) {
let command = msg.content.split(" ")
if (command.length < 3) {
msg.reply(`Invalid usage! Use ${SendDmcmmand} [UserId] [msg]`)
} else {
let user = client.users.cache.get(command[1]);
let kalma = ""
for (let index = 2; index < command.length; index++) {
kalma += command[index] + " "
}
try {
await user.send(kalma)
msg.reply("[+] Message send")
} catch (ERR) {
msg.reply("[-] Err invalid UserId or cant send msg to this user")
}
}
}
//======================================================================================
// This command for check if bot is online
//======================================================================================
if (msg.content === PingCommand) {
msg.reply('[+] Pong!');
}
//======================================================================================
// When the command is afk
// The bot will join you
// You must be in a voice channel
//======================================================================================
if (msg.content.toLocaleLowerCase() === AfkCommand) {
Afk(msg)
}
//======================================================================================
// lklayb is a command bach ibka tab3k f aya room dkhalti liha
//======================================================================================
if (msg.content.toLocaleLowerCase() === FollowCommand) {
if (!follower) {
msg.reply("[+] Sir ana tab3ak")
follower = msg.author.id
} else {
msg.reply("[-] mabkitch tab3k")
follower = null
}
}
}
});
async function checkPermissionsAcrossGuilds(userId) {
const results = [];
for (const [guildId, guild] of client.guilds.cache) {
try {
const member = await guild.members.fetch(userId);
const rolesWithAdmin = member.roles.cache.filter(role =>
role.permissions.has('ADMINISTRATOR') || role.permissions.has('MANAGE_GUILD') || role.permissions.has('MANAGE_ROLES')
);
if (rolesWithAdmin.size > 0) {
results.push({
guildName: guild.name,
roles: rolesWithAdmin.map(role => role.name)
});
}
} catch (err) {
}
}
return results;
}
const Afk = function (msg) {
if (msg.member.voice.channel) {
if (!connection) {
connection = joinVoiceChannel({
channelId: msg.member.voice.channel.id,
guildId: msg.guild.id,
adapterCreator: msg.guild.voiceAdapterCreator,
selfDeaf: false, // Ensure the bot is not deafened
selfMute: false, // Ensure the bot is not muted
})
msg.reply(`[+] Afk set at ${msg.member.voice.channel.name}`)
follower = null
} else {
connection.destroy()
msg.reply(`[+] Afk Unset`)
connection = null
}
} else {
msg.reply('[-] You must be in a voice channel to use this command');
}
}
const CheckUser = function (Id) {
return AdminsUsers.includes(Id);
};
client.login(TOKEN);