my bot is unable to read messages

const { Client, GatewayIntentBits, Intents } = require('discord.js');
const { joinVoiceChannel, createAudioResource, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
const { createWriteStream } = require('fs');
const prism = require('prism-media');
const { pipeline } = require('stream');

// Define the bot client
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILD_VOICE_STATES, // Use GUILD_VOICE_STATES instead of GuildVoiceStates
  ],
});


// Define a collection to store voice connections
client.voiceConnections = new Map();

// Event: When the bot is ready
client.once('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
});

// Event: When a message is received
client.on('messageCreate', async (message) => {
  console.log(`message`)
  // Check if the message author is a bot
  if (message.author.bot) return;

  // Check if the message starts with the command !record
  if (message.content=='!record') {
    // Check if the author is in a voice channel
    const voiceChannel = message.member?.voice.channel;
    if (!voiceChannel) {
      return message.reply('You must be in a voice channel to use this command!');
    }

    // Check if the bot is already in a voice connection in the guild
    if (client.voiceConnections.has(message.guild.id)) {
      return message.reply('I am already recording in a voice channel!');
    }

 
client.login(process.env.TOKEN);
Was this page helpful?