-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.ts
65 lines (49 loc) · 1.49 KB
/
index.ts
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
import "dotenv/config";
import { createAudioPlayer, createAudioResource, joinVoiceChannel, NoSubscriberBehavior } from '@discordjs/voice';
import play from 'play-dl';
import { ActivityType, ChannelType, Client, GatewayIntentBits } from "discord.js";
const { URL, CHANNELID, TOKEN, STATUS } = process.env;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
]
});
if(!CHANNELID || !Number(CHANNELID)) {
console.error("Invalid channel ID!");
}
if(!TOKEN) {
console.error("Invalid token!");
}
if(!URL || !play.yt_validate(URL)) {
console.error("Invalid URL!");
}
client.on("ready", async () => {
client.user.setActivity(STATUS || "Radio CODE-FI", { type: ActivityType.Listening });
const channel = await client.channels.fetch(CHANNELID);
if(!channel || channel.type !== ChannelType.GuildVoice) {
return console.error("Invalid channel!");
}
try {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});
const stream = await play.stream(URL);
const resource = createAudioResource(stream.stream, {
inputType: stream.type
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play
}
});
player.play(resource);
connection.subscribe(player);
} catch(err) {
console.error(err);
}
console.log("CODE-FI Online!");
});
client.login(TOKEN);