-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
173 lines (153 loc) · 5.36 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
const fs = require("fs");
const config = require("./config.json");
const {
Client,
GatewayIntentBits,
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
PermissionsBitField,
Partials,
} = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
],
partials: [Partials.GuildMember],
});
client.once("ready", () => {
console.log("Bot is Ready!");
console.log("Code by Wick Studio");
console.log("discord.gg/wicks");
});
client.on("messageCreate", async (message) => {
if (!message.content.startsWith("!bc") || message.author.bot) return;
const allowedRoleId = config.allowedRoleId;
const member = message.guild.members.cache.get(message.author.id);
if (!member.roles.cache.has(allowedRoleId)) {
return message.reply({
content: "ليس لديك صلاحية لاستخدام هذا الامر!",
ephemeral: true,
});
}
if (!message.member.permissions.has(PermissionsBitField.Flags.Administrator)) {
return message.reply({
content: "ليس لديك صلاحية لاستخدام هذا الامر!",
ephemeral: true,
});
}
const embed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle("لوحة تحكم البرودكاست")
.setImage(config.image)
.setDescription("الرجاء اختيار نوع الارسال للاعضاء.");
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("send_all")
.setLabel("ارسل للجميع")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId("send_online")
.setLabel("ارسل للمتصلين")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId("send_offline")
.setLabel("ارسل للغير المتصلين")
.setStyle(ButtonStyle.Danger),
);
await message.reply({
embeds: [embed],
components: [row],
ephemeral: true,
});
});
client.on("interactionCreate", async (interaction) => {
try {
if (interaction.isButton()) {
let customId;
if (interaction.customId === "send_all") {
customId = "modal_all";
} else if (interaction.customId === "send_online") {
customId = "modal_online";
} else if (interaction.customId === "send_offline") {
customId = "modal_offline";
}
const modal = new ModalBuilder()
.setCustomId(customId)
.setTitle("Type your message");
const messageInput = new TextInputBuilder()
.setCustomId("messageInput")
.setLabel("اكتب رسالتك هنا")
.setStyle(TextInputStyle.Paragraph);
modal.addComponents(new ActionRowBuilder().addComponents(messageInput));
await interaction.showModal(modal);
}
if (interaction.isModalSubmit()) {
const message = interaction.fields.getTextInputValue("messageInput");
const guild = interaction.guild;
if (!guild) return;
await interaction.deferReply({
ephemeral: true,
});
if (interaction.customId === "modal_all") {
const membersToSend = guild.members.cache.filter(
(member) => !member.user.bot
);
await Promise.all(
membersToSend.map(async (member) => {
try {
await member.send({ content: `${message}\n<@${member.user.id}>`, allowedMentions: { parse: ['users'] } });
} catch (error) {
console.error(`Error sending message to ${member.user.tag}:`, error);
}
})
);
} else if (interaction.customId === "modal_online") {
const onlineMembersToSend = guild.members.cache.filter(
(member) =>
!member.user.bot &&
member.presence &&
member.presence.status !== "offline"
);
await Promise.all(
onlineMembersToSend.map(async (member) => {
try {
await member.send({ content: `${message}\n<@${member.user.id}>`, allowedMentions: { parse: ['users'] } });
} catch (error) {
console.error(`Error sending message to ${member.user.tag}:`, error);
}
})
);
} else if (interaction.customId === "modal_offline") {
const offlineMembersToSend = guild.members.cache.filter(
(member) =>
!member.user.bot &&
(!member.presence || member.presence.status === "offline")
);
await Promise.all(
offlineMembersToSend.map(async (member) => {
try {
await member.send({ content: `${message}\n<@${member.user.id}>`, allowedMentions: { parse: ['users'] } });
} catch (error) {
console.error(`Error sending message to ${member.user.tag}:`, error);
}
})
);
}
await interaction.editReply({
content: "تم ارسال رسالتك الى الاعضاء بنجاح.",
});
}
} catch (error) {
console.error("Error in interactionCreate event:", error);
}
});
client.login(config.TOKEN);