Update Play command

This commit is contained in:
Christer Warén 2023-06-06 07:03:21 +03:00
parent 78d6b92dbd
commit c181066c67

View File

@ -22,10 +22,10 @@ export default {
}); });
} }
let query : number | string | null = null; let query: string | null = null;
if(interaction.isChatInputCommand()){ if(interaction.isChatInputCommand()){
query = interaction.options?.getNumber("query"); query = interaction.options?.getString("query");
} }
if(interaction.isStringSelectMenu()){ if(interaction.isStringSelectMenu()){
@ -37,22 +37,27 @@ export default {
} }
const radio = client.radio?.get(interaction.guild?.id); const radio = client.radio?.get(interaction.guild?.id);
if(!(interaction.member instanceof GuildMember)) return; if(!(interaction.member instanceof GuildMember)) return;
const voiceChannel = interaction.member?.voice.channel; const voiceChannel = interaction.member?.voice.channel;
if (!voiceChannel) return interaction.reply({ if (!voiceChannel) return interaction.reply({
content: client.messages.emojis["error"] + client.messages.noVoiceChannel, content: client.messages.emojis["error"] + client.messages.noVoiceChannel,
ephemeral: true ephemeral: true
}); });
if (radio) { if (radio) {
if (voiceChannel !== radio.voiceChannel) return interaction.reply({ if (voiceChannel !== radio.voiceChannel) return interaction.reply({
content: client.messages.emojis["error"] + client.messages.wrongVoiceChannel, content: client.messages.emojis["error"] + client.messages.wrongVoiceChannel,
ephemeral: true ephemeral: true
}); });
} }
if (!query) return interaction.reply({ if (!query) return interaction.reply({
content: client.messages.noQuery, content: client.messages.noQuery,
ephemeral: true ephemeral: true
}); });
const permissions = voiceChannel.permissionsFor(interaction.client.user); const permissions = voiceChannel.permissionsFor(interaction.client.user);
if (!permissions?.has(PermissionFlagsBits.Connect)) { if (!permissions?.has(PermissionFlagsBits.Connect)) {
return interaction.reply({ return interaction.reply({
@ -68,9 +73,9 @@ export default {
} }
let station; let station;
if (typeof query === 'number') { if(!isNaN(parseInt(query) - 1)){
const number = parseInt((query - 1) as unknown as string); let number = parseInt(query) - 1;
if (number > client.stations.length - 1) { if(number > client.stations.length - 1) {
return interaction.reply({ return interaction.reply({
content: client.messages.emojis["error"] + client.messages.wrongStationNumber, content: client.messages.emojis["error"] + client.messages.wrongStationNumber,
ephemeral: true ephemeral: true
@ -79,20 +84,16 @@ export default {
station = client.stations[number]; station = client.stations[number];
} }
} else { } else {
if(!(typeof query === 'string')) return;
if(query.length < 3) return interaction.reply({ if(query.length < 3) return interaction.reply({
content: client.messages.emojis["error"] + client.messages.tooShortSearch, content: client.messages.emojis["error"] + client.messages.tooShortSearch,
ephemeral: true ephemeral: true
}); });
let type = ""; let type = "text";
if(interaction.isStringSelectMenu()){ if(interaction.isStringSelectMenu() && interaction.values?.[0]){
if(interaction.values?.[0]){ type = "direct";
type = "direct";
} else {
type = "text";
}
} }
const sstation = await client.stations.search(query, type); const sstation = await client.stations.search(query, type);