Files
dj-spangebob/src/commands/play.ts
Patryk Koreń ad87d3fbb8 Add an overlay soundboard and fix playback command bugs.
Stop was advancing the queue, history overwrote the day file, and slash commands often never replied; soundboard clips now mix on top of the current track.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 17:03:02 +02:00

53 lines
1.7 KiB
TypeScript

import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { connectToChannelByInteraction } from '../util/helpers';
import { requestSong } from '../playback';
import { msg_downloading, msg_play, msg_searching } from '../messages';
import { search, spotifyToYouTube } from '../util/downloader';
const name = "play"
function register() {
return new SlashCommandBuilder()
.setName(name)
.setDescription('YT')
.addStringOption((option) => option.setName("url")
.setDescription("YT url/search")
.setRequired(true))
}
async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try {
await interaction.deferReply()
await connectToChannelByInteraction(interaction)
const input = interaction.options.getString("url")!;
let url: string;
if (input.startsWith("https://open.spotify.com/")) {
await interaction.editReply(msg_searching(input));
url = await spotifyToYouTube(input)
}
else if (input.startsWith("http")) {
url = input
} else {
await interaction.editReply(msg_searching(input));
url = await search(input)
console.log(input, url)
}
await interaction.editReply(msg_downloading(url));
await requestSong(url, { user: interaction.user.username })
await interaction.editReply(msg_play());
} catch (error) {
console.error(error);
const message = error instanceof Error ? error.message : 'Coś poszło nie tak :/'
await interaction.editReply(message);
}
}
export default {
name,
register,
execute
}