Advertisement
Guest User

Untitled

a guest
Jan 15th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. import { Client, GatewayIntentBits, REST, Routes } from 'discord.js';
  2. import { Player, QueryType } from 'discord-player';
  3.  
  4. const client = new Client({
  5. intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates],
  6. });
  7.  
  8. client.player = new Player(client, {
  9. ytdlOptions: {
  10. quality: 'highestaudio',
  11. highWaterMark: 1 << 25,
  12. },
  13. });
  14.  
  15. const commands = [
  16. {
  17. name: 'play',
  18. description: 'Play song!',
  19. },
  20. {
  21. name: 'skip',
  22. description: 'Skip song!',
  23. },
  24. ];
  25.  
  26. const rest = new REST({ version: '10' }).setToken(
  27. 'TOKEN'
  28. );
  29.  
  30. client.on('ready', () => {
  31. console.log('Bot is ready!');
  32.  
  33. let guilds = client.guilds.cache.map((g) => g.id);
  34. guilds.forEach(async (id) => {
  35. try {
  36. const data = await rest.put(Routes.applicationGuildCommands('CLIENT_ID', id), {
  37. body: commands,
  38. });
  39. console.log(`Successfully reloaded ${data.length} application (/) commands.`);
  40. } catch (err) {
  41. console.log(err);
  42. }
  43. });
  44. });
  45.  
  46. client.on('interactionCreate', async (interaction) => {
  47. if (interaction.type !== 2) return;
  48.  
  49. if (interaction.commandName === 'play') {
  50. console.log('Issued play command');
  51. const queue = await client.player.createQueue(interaction.guild);
  52. if (!queue.connection) await queue.connect(interaction.member.voice.channel);
  53.  
  54. const result = await client.player.search(
  55. 'https://www.youtube.com/playlist?list=PL2TRsgSGFUWp4BfAs4fi6tUvBs-6yxrWK',
  56. {
  57. requestedBy: interaction.user,
  58. searchEngine: QueryType.AUTO,
  59. }
  60. );
  61.  
  62. result.playlist ? queue.addTracks(result.tracks) : queue.addTrack(result.tracks[0]);
  63.  
  64. let tracksArray = [];
  65. queue.tracks.forEach((track) => {
  66. tracksArray.push(track.title);
  67. });
  68.  
  69. console.log(tracksArray);
  70. await queue.play();
  71. }
  72.  
  73. if (interaction.commandName === 'skip') {
  74. console.log('Issued skip command');
  75. const queue = await client.player.createQueue(interaction.guild);
  76. if (!queue.connection) return interaction.reply('no queue');
  77.  
  78. await queue.skip();
  79. }
  80. });
  81.  
  82. client.player.on('trackStart', (queue, track) => {
  83. console.log(`Started track ${track}`);
  84. });
  85.  
  86. client.login("TOKEN");
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement