all repos — simple-discord-music-bot @ 34d90ffd27e2def867cb627ae49aad8e3431fde3

A Discord bot making use of discord.js and play-yt.

src/functions/music.ts (view raw)

 1import { ChatInputCommandInteraction, VoiceBasedChannel } from 'discord.js'
 2import { YouTubeVideo } from 'play-dl';
 3import MyQueue from './myqueue';
 4
 5const queues = new Map<string, MyQueue>();
 6
 7export function getQueue(server: string): MyQueue {
 8    if (queues.has(server))
 9        return queues.get(server);
10    
11    const q = new MyQueue();
12    queues.set(server, q);
13    return q;
14}
15
16export function formatTitle(video: YouTubeVideo): string {
17    return `**${video.title}** (\`${video.durationRaw}\`)`;
18}
19
20export async function getChannel(interaction: ChatInputCommandInteraction): Promise<string | VoiceBasedChannel>{
21    const member = interaction.member;
22    if (!member)
23        return 'Please use this in your current server.';
24
25    const vc_error = 'You\'re not in a voice channel.';
26
27    if (!("voice" in member)) return vc_error;
28    const channel: VoiceBasedChannel = member.voice.channel;
29    return channel ? channel : vc_error;
30}