title: I am having a problem with Discord.js code I have not found a solution
body: <p>It gives an error that when I input the command -play music it gives this:</p>
  <p>C:\Users\User\Desktop\Discord Bot JS\commands\play.js:8
  const voiceChannel = message.member.voice.channel;
  ^</p>
  <pre><code>TypeError: Cannot read properties of undefined (reading 'voice')
      at Object.execute (C:\Users\User\Desktop\Discord Bot JS\commands\play.js:8:45)
      at Client.&lt;anonymous&gt; (C:\Users\User\Desktop\Discord Bot JS\main.js:37:37)
      at Client.emit (node:events:527:28)
      at MessageCreateAction.handle (C:\Users\User\Desktop\Discord Bot JS\node_modules\discord.js\src\client\actions\Messag    at WebSocketShard.onPacket (C:\Users\User\Desktop\Discord Bot JS\node_modules\discord.js\src\client\websocket\WebSock    at WebSocketShard.onPacket (C:\Users\User\Desktop\Discord Bot JS\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)    at WebSocketShard.onMessage (C:\Users\User\Desktop\Discord Bot JS\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
      at WebSocket.onMessage (C:\Users\User\Desktop\Discord Bot JS\node_modules\ws\lib\event-target.js:132:16)    at WebSocket.emit (node:events:527:28)
  PS C:\Users\User\Desktop\Discord Bot JS&gt;
  </code></pre>
  <p>heres the code</p>
  <pre><code>const ytdl = require('ytdl-core');
  const ytSearch = require('yt-search');
   
  module.exports = {
      name: 'play',
      description: 'Joins and plays a video from youtube',
      async execute(client, message, args) {
          const voiceChannel = message.member.voice.channel;
   
          if (!voiceChannel) return message.channel.send('You need to be in a channel to execute this command!');
          const permissions = voiceChannel.permissionsFor(message.client.user);
          if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct permissins');
          if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct permissins');
          if (!args.length) return message.channel.send('You need to send the second argument!');
   
          const validURL = (str) =&gt;{
              var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&amp;%!\-\/]))?/;
              if(!regex.test(str)){
                  return false;
              } else {
                  return true;
              }
          }
   
          if(validURL(args[0])){
   
              const  connection = await voiceChannel.join();
              const stream  = ytdl(args[0], {filter: 'audioonly'});
   
              connection.play(stream, {seek: 0, volume: 1})
              .on('finish', () =&gt;{
                  voiceChannel.leave();
                  message.channel.send('leaving channel');
              });
   
              await message.reply(`:thumbsup: Now Playing ***Your Link!***`)
   
              return
          }
   
          
          const connection = await voiceChannel.join();
   
          const videoFinder = async (query) =&gt; {
              const videoResult = await ytSearch(query);
   
              return (videoResult.videos.length &gt; 1) ? videoResult.videos[0] : null;
   
          }
   
          const video = await videoFinder(args.join(' '));
   
          if(video){
              const stream  = ytdl(video.url, {filter: 'audioonly'});
              connection.play(stream, {seek: 0, volume: 1})
              .on('finish', () =&gt;{
                  voiceChannel.leave();
              });
   
              await message.reply(`:thumbsup: Now Playing ***${video.title}***`)
          } else {
              message.channel.send('No video results found');
          }
      }
  }
  </code></pre>
  <p>I got the code from a youtube tutorial and I looked for many solutions that eventually did not work.</p>