Advertisement
Guest User

Untitled

a guest
Sep 5th, 2023
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. const { Client, GatewayIntentBits } = require('discord.js');
  2. const { Player } = require('discord-player');
  3.  
  4. const client = new Client({
  5. intents: [
  6. GatewayIntentBits.Guilds,
  7. GatewayIntentBits.GuildMessages,
  8. GatewayIntentBits.GuildVoiceStates,
  9. GatewayIntentBits.MessageContent, // Add MESSAGE CONTENT INTENT
  10. ],
  11. });
  12.  
  13. const player = new Player(client, {
  14. youtubeKey: 'AIzaSyDjImSQ-3JMrrjG70hS2r4Hp-vO3W70IgQ', // Replace with your YouTube API key
  15. });
  16.  
  17. client.once('ready', () => {
  18. console.log(`Logged in as ${client.user.tag}`);
  19. });
  20.  
  21. const prefix = '!'; // Command prefix
  22.  
  23. client.on('messageCreate', async (message) => {
  24. if (!message.guild) return;
  25.  
  26. if (message.content.startsWith(prefix)) {
  27. const args = message.content.slice(prefix.length).trim().split(/ +/);
  28. const command = args.shift().toLowerCase();
  29.  
  30. if (command === 'play') {
  31. const query = args.join(' ');
  32.  
  33. if (!query) {
  34. message.channel.send('Please provide a valid YouTube URL or search query.');
  35. return;
  36. }
  37.  
  38. const voiceChannel = message.member.voice.channel;
  39. if (!voiceChannel) {
  40. message.channel.send('You need to be in a voice channel to use this command.');
  41. return;
  42. }
  43.  
  44. try {
  45. const song = await player.play(voiceChannel, query);
  46. message.channel.send(`Now playing: ${song.name}`);
  47. } catch (error) {
  48. console.error('Error playing the song:', error);
  49. message.channel.send('An error occurred while playing the song.');
  50. }
  51. }
  52. // Add more command handling here...
  53. }
  54. });
  55.  
  56. client.login('MTE0ODExNTcwMTg2MTcxNjAwOA.GFXTBm.Y8eCJ6E5fH0S4ySsMyoJMleCp1VmEbfRMJpYJY'); // Replace with your bot token
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement