added search

This commit is contained in:
Patryk Koreń
2025-12-28 11:31:45 +01:00
parent b551cce62a
commit 03c2d35bf0
4 changed files with 57 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'dis
import { connectToChannelByInteraction } from '../util/helpers';
import { forceRequestSong } from '../playback';
import { getPlayMsg } from '../messages';
import { search } from '../util/downloader';
const name = "forceplay"
@@ -16,16 +17,27 @@ function register() {
async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try {
await interaction.deferReply()
connectToChannelByInteraction(interaction)
const url = interaction.options.getString("url")!;
const input = interaction.options.getString("url")!;
let url: string;
if (input.startsWith("http")) {
url = input
} else {
url = await search(input)
await interaction.editReply(`searching for: ${input}`);
console.log(input, url)
}
await forceRequestSong(interaction, url)
const msg = getPlayMsg(url)
await interaction.reply(msg);
await interaction.editReply(msg);
} catch (error) {
console.error(error);
await interaction.reply('Coś poszło nie tak :/');
await interaction.editReply('Coś poszło nie tak :/');
}
}

View File

@@ -2,6 +2,7 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'dis
import { connectToChannelByInteraction } from '../util/helpers';
import { requestSong } from '../playback';
import { getPlayMsg } from '../messages';
import { search } from '../util/downloader';
const name = "play"
@@ -10,22 +11,33 @@ function register() {
.setName(name)
.setDescription('YT')
.addStringOption((option) => option.setName("url")
.setDescription("YT url")
.setDescription("YT url/search")
.setRequired(true))
}
async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try {
await interaction.deferReply()
connectToChannelByInteraction(interaction)
const url = interaction.options.getString("url")!;
const input = interaction.options.getString("url")!;
let url: string;
if (input.startsWith("http")) {
url = input
} else {
url = await search(input)
await interaction.editReply(`searching for: ${input}`);
console.log(input, url)
}
await requestSong(interaction, url)
const msg = getPlayMsg(url)
await interaction.reply(msg);
await interaction.editReply(msg);
} catch (error) {
console.error(error);
await interaction.reply('Coś poszło nie tak :/');
await interaction.editReply('Coś poszło nie tak :/');
}
}