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);

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);
11 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs14mo ago
If you aren't getting content, embeds or attachments of a message, make sure you have the MessageContent intent enabled in the Developer Portal and provide it to your client:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
theold.kingu
theold.kinguOP14mo ago
it is
SpecialSauce
SpecialSauce14mo ago
Show the client constructor nevermind it’s right there. Is the messageCreate event firing?
theold.kingu
theold.kinguOP14mo ago
no it aint firing
duck
duck14mo ago
it is not you do not have the MESSAGE_CONTENT intent
theold.kingu
theold.kinguOP14mo ago
wait
// Define the bot client
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.MESSAGE_CONTENT// Use GUILD_VOICE_STATES instead of GuildVoiceStates
],
});
// Define the bot client
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.MESSAGE_CONTENT// Use GUILD_VOICE_STATES instead of GuildVoiceStates
],
});
this too aint working oh man i almost tried everything even gpt ;=; @duck @SpecialSauce
SpecialSauce
SpecialSauce14mo ago
Is the ready event firing?
theold.kingu
theold.kinguOP14mo ago
yes it is i mean that the only god damn thing working right dogeHaHa
duck
duck14mo ago
just to clarify when you said "it aint firing", are you just referring to the event not behaving as expected to do you mean that you aren't receiving the word message in your logs?
theold.kingu
theold.kinguOP14mo ago
ya the word message aint logged and also the if statement there is not running yes it is online and do also have admin perms
Want results from more Discord servers?
Add your server