Files
dj-spangebob/src/commands/forceplay.ts

50 lines
1.5 KiB
TypeScript

import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { connectToChannelByInteraction } from '../util/helpers';
import { forceRequestSong } from '../playback';
import { getPlayMsg, msg_downloading, msg_play, msg_searching } from '../messages';
import { search } from '../util/downloader';
const name = "forceplay"
function register() {
return new SlashCommandBuilder()
.setName(name)
.setDescription('YT')
.addStringOption((option) => option.setName("url")
.setDescription("YT url")
.setRequired(true))
}
async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try {
await interaction.deferReply()
connectToChannelByInteraction(interaction)
const input = interaction.options.getString("url")!;
let url: string;
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));
forceRequestSong(url, { user: interaction.user.username }).then(() => {
// const msg = getPlayMsg(url)
interaction.editReply(msg_play());
})
} catch (error) {
console.error(error);
await interaction.editReply('Coś poszło nie tak :/');
}
}
export default {
name,
register,
execute
}