Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Client, GatewayIntentBits, REST, Routes } from 'discord.js';
- import { Player, QueryType } from 'discord-player';
- const client = new Client({
- intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates],
- });
- client.player = new Player(client, {
- ytdlOptions: {
- quality: 'highestaudio',
- highWaterMark: 1 << 25,
- },
- });
- const commands = [
- {
- name: 'play',
- description: 'Play song!',
- },
- {
- name: 'skip',
- description: 'Skip song!',
- },
- ];
- const rest = new REST({ version: '10' }).setToken(
- 'TOKEN'
- );
- client.on('ready', () => {
- console.log('Bot is ready!');
- let guilds = client.guilds.cache.map((g) => g.id);
- guilds.forEach(async (id) => {
- try {
- const data = await rest.put(Routes.applicationGuildCommands('CLIENT_ID', id), {
- body: commands,
- });
- console.log(`Successfully reloaded ${data.length} application (/) commands.`);
- } catch (err) {
- console.log(err);
- }
- });
- });
- client.on('interactionCreate', async (interaction) => {
- if (interaction.type !== 2) return;
- if (interaction.commandName === 'play') {
- console.log('Issued play command');
- const queue = await client.player.createQueue(interaction.guild);
- if (!queue.connection) await queue.connect(interaction.member.voice.channel);
- const result = await client.player.search(
- 'https://www.youtube.com/playlist?list=PL2TRsgSGFUWp4BfAs4fi6tUvBs-6yxrWK',
- {
- requestedBy: interaction.user,
- searchEngine: QueryType.AUTO,
- }
- );
- result.playlist ? queue.addTracks(result.tracks) : queue.addTrack(result.tracks[0]);
- let tracksArray = [];
- queue.tracks.forEach((track) => {
- tracksArray.push(track.title);
- });
- console.log(tracksArray);
- await queue.play();
- }
- if (interaction.commandName === 'skip') {
- console.log('Issued skip command');
- const queue = await client.player.createQueue(interaction.guild);
- if (!queue.connection) return interaction.reply('no queue');
- await queue.skip();
- }
- });
- client.player.on('trackStart', (queue, track) => {
- console.log(`Started track ${track}`);
- });
- client.login("TOKEN");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement