|
| 1 | +const { PermissionsBitField, ApplicationCommandOptionType, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } = require("discord.js"); |
| 2 | +const { Database } = require("st.db"); |
| 3 | +const ytsr = require("@distube/ytsr"); |
| 4 | + |
| 5 | +const GSetup = new Database("./settings/models/setup.json", { databaseInObject: true }); |
| 6 | + |
| 7 | +module.exports = { |
| 8 | + name: ["music", "searchtop"], |
| 9 | + description: "Search and queue song to the top.", |
| 10 | + category: "Music", |
| 11 | + options: [ |
| 12 | + { |
| 13 | + name: "search", |
| 14 | + type: ApplicationCommandOptionType.String, |
| 15 | + description: "The song to play.", |
| 16 | + required: true |
| 17 | + } |
| 18 | + ], |
| 19 | + run: async (client, interaction) => { |
| 20 | + const string = interaction.options.getString("search"); |
| 21 | + |
| 22 | + const db = await GSetup.get(interaction.guild.id); |
| 23 | + if (db.setup_enable === true) return interaction.reply("Command is disable already have song request channel!"); |
| 24 | + |
| 25 | + await interaction.reply(`🔍 **Searching...** \`${string}\``); |
| 26 | + |
| 27 | + const message = await interaction.fetchReply(); |
| 28 | + await client.createPlay(interaction, message.id); |
| 29 | + |
| 30 | + const { channel } = interaction.member.voice; |
| 31 | + if (!channel) return interaction.editReply("You need to be in voice channel.") |
| 32 | + if (!channel.permissionsFor(interaction.guild.members.me).has(PermissionsBitField.Flags.Connect)) return interaction.editReply(`I don't have perm \`CONNECT\` in ${channel.name} to join voice!`); |
| 33 | + if (!channel.permissionsFor(interaction.guild.members.me).has(PermissionsBitField.Flags.Speak)) return interaction.editReply(`I don't have perm \`SPEAK\` in ${channel.name} to join voice!`); |
| 34 | + |
| 35 | + const row = new ActionRowBuilder() |
| 36 | + .addComponents( |
| 37 | + new ButtonBuilder() |
| 38 | + .setCustomId("one") |
| 39 | + .setEmoji("1️⃣") |
| 40 | + .setStyle(ButtonStyle.Secondary) |
| 41 | + ) |
| 42 | + .addComponents( |
| 43 | + new ButtonBuilder() |
| 44 | + .setCustomId("two") |
| 45 | + .setEmoji("2️⃣") |
| 46 | + .setStyle(ButtonStyle.Secondary) |
| 47 | + ) |
| 48 | + .addComponents( |
| 49 | + new ButtonBuilder() |
| 50 | + .setCustomId("three") |
| 51 | + .setEmoji("3️⃣") |
| 52 | + .setStyle(ButtonStyle.Secondary) |
| 53 | + ) |
| 54 | + .addComponents( |
| 55 | + new ButtonBuilder() |
| 56 | + .setCustomId("four") |
| 57 | + .setEmoji("4️⃣") |
| 58 | + .setStyle(ButtonStyle.Secondary) |
| 59 | + ) |
| 60 | + .addComponents( |
| 61 | + new ButtonBuilder() |
| 62 | + .setCustomId("five") |
| 63 | + .setEmoji("5️⃣") |
| 64 | + .setStyle(ButtonStyle.Secondary) |
| 65 | + ) |
| 66 | + |
| 67 | + const options = { |
| 68 | + member: interaction.member, |
| 69 | + textChannel: interaction.channel, |
| 70 | + interaction, |
| 71 | + position: 1 |
| 72 | + } |
| 73 | + |
| 74 | + const res = await ytsr(string, { safeSearch: true, limit: 5 }); |
| 75 | + |
| 76 | + let index = 1; |
| 77 | + const result = res.items.slice(0, 5).map(x => `**(${index++}.) [${x.name}](${x.url})** Author: \`${x.author}\``).join("\n") |
| 78 | + |
| 79 | + const embed = new EmbedBuilder() |
| 80 | + .setAuthor({ name: `Song Selection...`, iconURL: interaction.guild.iconURL({ dynamic: true }) }) |
| 81 | + .setColor(client.color) |
| 82 | + .setDescription(result) |
| 83 | + .setFooter({ text: `Please response in 30s` }) |
| 84 | + |
| 85 | + await message.edit({ content: " ", embeds: [embed], components: [row] }); |
| 86 | + |
| 87 | + const collector = interaction.channel.createMessageComponentCollector({ filter: (m) => m.user.id === interaction.user.id, time: 30000, max: 1 }); |
| 88 | + |
| 89 | + collector.on('collect', async (interaction) => { |
| 90 | + const id = interaction.customId; |
| 91 | + const loader = new EmbedBuilder() |
| 92 | + .setDescription("**Loading please wait....**") |
| 93 | + |
| 94 | + |
| 95 | + if(id === "one") { |
| 96 | + await message.edit({ embeds: [loader], components: [] }); |
| 97 | + await client.distube.play(interaction.member.voice.channel, res.items[0].url, options); |
| 98 | + } else if(id === "two") { |
| 99 | + await message.edit({ embeds: [loader], components: [] }); |
| 100 | + await client.distube.play(interaction.member.voice.channel, res.items[1].url, options); |
| 101 | + } else if(id === "three") { |
| 102 | + await message.edit({ embeds: [loader], components: [] }); |
| 103 | + await client.distube.play(interaction.member.voice.channel, res.items[2].url, options); |
| 104 | + } else if(id === "four") { |
| 105 | + await message.edit({ embeds: [loader], components: [] }); |
| 106 | + await client.distube.play(interaction.member.voice.channel, res.items[3].url, options); |
| 107 | + } else if(id === "five") { |
| 108 | + await message.edit({ embeds: [loader], components: [] }); |
| 109 | + await client.distube.play(interaction.member.voice.channel, res.items[4].url, options); |
| 110 | + } |
| 111 | + }); |
| 112 | + |
| 113 | + collector.on('end', async (collected, reason) => { |
| 114 | + if(reason === "time") { |
| 115 | + message.edit({ content: `No Response`, embeds: [], components: [] }); |
| 116 | + } |
| 117 | + }); |
| 118 | + } |
| 119 | +} |
0 commit comments