0

I'm trying to run a Discord bot using the discord.js library, but I'm getting the following error: TypeError: Cannot read properties of undefined (reading 'GUILD_MESSAGES'). I have installed the latest version of the discord.js library and enabled the relevant intents in the Discord Developer Portal, but the error persists. Here is my code:

const Discord = require('discord.js');

// Specify which intents the client should have access to
const intents = new Discord.Intents([
    Discord.Intents.GUILD_MESSAGES,
    Discord.Intents.DIRECT_MESSAGES
]);

// Pass the intents array as an option when creating the Client object
const client = new Discord.Client({ intents: Discord.Intents.ALL });

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', message => {
    if (message.content === '!ping') {
        // Get a list of all guild channels
        const channels = message.guild.channels.cache;
        // Select a random channel from the list
        const channel = channels.random();
        // Get a list of all members in the channel
        const members = channel.members.array();
        // Select a random member from the list
        const member = members[Math.floor(Math.random() * members.length)];
        // Send a message to the channel mentioning the random member
        channel.send(`${member}, you have been pinged!`)
only1smokey
  • 21
  • 1
  • 7
  • Closed as duplicate. In v14, you'll need to use `GatewayIntentBits`. You'll also have issues with `message.content` being an empty string, so check out this answer too: https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js?noredirect=1&lq=1 – Zsolt Meszaros Dec 23 '22 at 09:16
  • I can't see in the docs where Intents is being called/created, but it might be that you have to first create the `intents` variable and then add in the `GUILD_MESSAGES` and `DIRECT_MESSAGES` after? – Harrison Dec 23 '22 at 09:16

0 Answers0