-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
226 lines (215 loc) Β· 7.55 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
const Discord = require("discord.js");
const voiceDiscord = require(`@discordjs/voice`);
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.MessageContent,
],
});
const { token, prefix, ownerid } = require("./botconfig/config.json");
const { Database } = require("beta.db");
const fs = require("fs");
const db = new Database("./db/role.json");
const radio = require(`./botconfig/radiostation.json`);
client.once(Discord.Events.ClientReady, () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setActivity("Coded By : Hesam TooVinS", {
type: Discord.ActivityType.Listening,
}); //You can change type to : LISTENING , COMPETING , PLAYING
});
client.on(Discord.Events.MessageCreate, async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(" ");
const command = args.shift().toLowerCase();
//help menu
if (command === "help") {
const helpembed = new Discord.EmbedBuilder()
.setTitle("π» Help menu")
.addFields(
{ name: `${prefix}radio`, value: "play radio ", inline: true },
{
name: `${prefix}radiolist`,
value: "list of popular radio station",
inline: true,
},
{ name: `${prefix}stats`, value: "stats of bot", inline: true },
{
name: `${prefix}setrole`,
value: "Set role to Control Bot",
inline: true,
},
{ name: `${prefix}reset`, value: "Restart Bot", inline: true },
{ name: `${prefix}dc`, value: "Disconnect Bot", inline: true }
)
.setThumbnail(
`https://play-lh.googleusercontent.com/oV1AVbkOV2M7rqOAENeuNAnBL6ftRpECFDiiKU4w19tX_rTHTnwJRrPcJ2yy270taMU`
)
.setFooter({
text: `Requested By ${message.author.username}`,
iconURL: message.author.displayAvatarURL({
extension: "png",
dynamic: true,
}),
})
.setColor("Green")
.setTimestamp();
message.reply({ embeds: [helpembed] });
}
// radio list you can pick radio id and play
if (command == `radiolist`) {
fs.readFile("./botconfig/radioid.json", "utf8", function (err, contents) {
const radioidembed = new Discord.EmbedBuilder()
.setTitle("Radio Id List")
.setDescription("```json\n" + contents + "\n```")
.setFooter({
text: `Requested By ${message.author.username}`,
iconURL: message.author.displayAvatarURL({
extension: "png",
dynamic: true,
}),
})
.setColor("GREEN")
.setTimestamp();
message.reply({ embeds: [radioidembed] });
});
}
//set role for some cmd s
if (command == "setrole") {
if (message.author.id !== `${ownerid}`)
return message.reply({
content: `:x: **You Dont Have permission to use this command!** `,
});
if (!args[0])
return message.reply({
content: `:x: **You forgot to enter a Role Id!**`,
});
db.set("role", args[0]);
db.set("Guildid", message.guild.id);
message.reply({ content: `β
**role was set**` });
}
//radio player
if (command == "radio") {
const role = db.get("role");
if (message.author.id !== ownerid && !message.member.roles.cache.has(role))
return message.reply({
content: `:x: **You Dont Have permission to use this command! , you need <@&${role}> role**`,
});
if (!args[0])
return message.reply({
content:
":x: **You forgot to enter a Voice-Channel Id!** \n **Usage** : ``!radio [voiceid] [radioid]`` \n **e.g** : ``!radio 879417192553271367 2``",
});
if (args[0] % 1 != 0 || args[1] <= 0)
return message.reply({
content:
":x: **You forgot to enter a Radio Id!** \n **Usage** : ``!radio [voiceid] [1-15]`` \n **e.g** : ``!radio 879417192553271367 2``",
});
if (!args[1])
return message.reply({
content:
":x: **You forgot to enter a Radio Id!** \n **Usage** : ``!radio [voiceid] [radioid]`` \n **e.g** : ``!radio 879417192553271367 2``",
});
if (args[1] % 1 != 0 || args[1] <= 0)
return message.reply({
content:
":x: **You forgot to enter a Radio Id!** \n **Usage** : ``!radio [voiceid] [1-15]`` \n **e.g** : ``!radio 879417192553271367 2``",
});
if (args[1] > 15)
return message.reply({
content:
":x: **You forgot to enter a Radio Id!** \n **Usage** : ``!radio [voiceid] [1-15]`` \n **e.g** : ``!radio 879417192553271367 2``",
});
var connection = voiceDiscord.joinVoiceChannel({
channelId: args[0],
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
selfDeaf: true,
});
const player = voiceDiscord.createAudioPlayer();
const resource = voiceDiscord.createAudioResource(radio[args[1]]);
player.play(resource);
connection.subscribe(player);
player.on(voiceDiscord.AudioPlayerStatus.Idle, () => {
connection.destroy();
message.reply({ content: `:x:**Radio Station Has Been Destroyed!**` });
});
message.reply({ content: `π»**Radio Started**` });
}
//restart bot
if (command == `reset`) {
if (message.author.id !== `${ownerid}`)
return message.reply({
content: `:x: **You Dont Have permission to use this command!** `,
});
message.reply({ content: `**Start Restarting Bot**` });
client.destroy();
client.login(token);
message.channel.send({ content: `β
**Bot was successfully restarted**` });
}
// disconnect bot
if (command == `dc`) {
const role = db.get("role");
if (message.author.id !== ownerid && !message.member.roles.cache.has(role))
return message.reply({
content: `:x: **You Dont Have permission to use this command! , you need <@&${role}> role**`,
});
connection.destroy();
message.reply({ content: "β
**Bot was successfully Disconnected** " });
}
// bot stats
if (command == `stats`) {
const statsembed = new Discord.EmbedBuilder()
.addFields(
{
name: ":robot: Client",
value: `β\`π’ Online!\``,
inline: true,
},
{
name: "β Ping",
value: `β\`${Math.round(message.client.ws.ping)}ms\``,
inline: true,
},
{
name: ":file_cabinet: Memory",
value: `β\`${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(
2
)}mb\``,
inline: true,
},
{
name: ":robot: Version",
value: `β\`v${require("./package.json").version}\``,
inline: true,
},
{
name: ":blue_book: Discord.js",
value: `β\`v${Discord.version}\``,
inline: true,
},
{
name: ":green_book: Node",
value: `β\`${process.version}\``,
inline: true,
}
)
.setColor("Green")
.setFooter({
text: `Requested By ${message.author.username}`,
iconURL: message.author.displayAvatarURL({
extension: "png",
dynamic: true,
}),
})
.setTimestamp();
message.reply({ embeds: [statsembed] });
}
});
client.login(token);
/**********************************************************
* @INFO
* Bot Coded by hesam TooVinS#5284| https://discord.gg/Jhnqm5BHnt
*********************************************************/