-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.ts
56 lines (43 loc) · 1.57 KB
/
bot.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
import { Player, QueryType } from "discord-player"
import { SpotifyExtractor, SoundCloudExtractor } from "@discord-player/extractor"
import { YoutubeiExtractor } from "discord-player-youtubei"
import { Client, GatewayIntentBits } from "discord.js"
import { addEventListeners } from "./handlers/events.ts"
import { MusicBot } from "./types.ts"
import "dotenv/config"
import { logger } from "./utils/logging/logger.ts"
const TOKEN = process.env.TOKEN
const bot: MusicBot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
],
}) as MusicBot
bot.player = new Player(bot as Client, {
skipFFmpeg: true,
})
addEventListeners(bot).then(async () => {
await bot.player.extractors.register(YoutubeiExtractor, {
overrideBridgeMode: {
[QueryType.SPOTIFY_SEARCH]: "yt",
default: "ytmusic",
},
})
logger.info("Registered YoutubeiExtractor")
await bot.player.extractors.register(SpotifyExtractor, {})
logger.info("Registered SpotifyExtractor")
await bot.player.extractors.register(SoundCloudExtractor, {})
logger.info("Registered SoundCloudExtractor")
await bot.login(TOKEN)
})
// generateOauthTokens() // Run this once to generate the necessary tokens
// Handle uncaught exceptions and unhandled promise rejections
process.on("uncaughtException", (error) => {
console.error("There was an uncaught error", error, error.stack)
})
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise)
})