Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, GatewayIntentBits } = require('discord.js');
- const { Player } = require('discord-player');
- const client = new Client({
- intents: [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.GuildVoiceStates,
- GatewayIntentBits.MessageContent, // Add MESSAGE CONTENT INTENT
- ],
- });
- const player = new Player(client, {
- youtubeKey: 'AIzaSyDjImSQ-3JMrrjG70hS2r4Hp-vO3W70IgQ', // Replace with your YouTube API key
- });
- client.once('ready', () => {
- console.log(`Logged in as ${client.user.tag}`);
- });
- const prefix = '!'; // Command prefix
- client.on('messageCreate', async (message) => {
- if (!message.guild) return;
- if (message.content.startsWith(prefix)) {
- const args = message.content.slice(prefix.length).trim().split(/ +/);
- const command = args.shift().toLowerCase();
- if (command === 'play') {
- const query = args.join(' ');
- if (!query) {
- message.channel.send('Please provide a valid YouTube URL or search query.');
- return;
- }
- const voiceChannel = message.member.voice.channel;
- if (!voiceChannel) {
- message.channel.send('You need to be in a voice channel to use this command.');
- return;
- }
- try {
- const song = await player.play(voiceChannel, query);
- message.channel.send(`Now playing: ${song.name}`);
- } catch (error) {
- console.error('Error playing the song:', error);
- message.channel.send('An error occurred while playing the song.');
- }
- }
- // Add more command handling here...
- }
- });
- client.login('MTE0ODExNTcwMTg2MTcxNjAwOA.GFXTBm.Y8eCJ6E5fH0S4ySsMyoJMleCp1VmEbfRMJpYJY'); // Replace with your bot token
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement