OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Issue with discord.js , Cannot read properties of undefined (reading 'GUILD_MESSAGES')

  • Thread starter Thread starter Ondrej
  • Start date Start date
O

Ondrej

Guest
I have this issue with my discord bot code. In this case even ChatGPT won't help. Do you know what the issue could be ? I've tried interpreting the code in other way and asking ChatGPT but none of that helped. Thank you in advance

The stackowerflow requires to add more details but I don't known what to add else so just please ignore this text.

Lorem ipsum dolor sit amet consectetur adipiscing elit arcu parturient hendrerit, tellus metus consequat montes sagittis porttitor dui eros cras, sodales neque ex euismod ac natoque mauris tempor lacinia. Semper est dictum potenti mattis iaculis praesent curabitur non egestas tempor litora, sed luctus ligula facilisis sodales duis maximus conubia orci vel, quis eu eget elit penatibus dis aliquet mi pulvinar facilisi. Ullamcorper lacus gravida ex curabitur parturient nam bibendum ipsum mus, netus tempor commodo justo sociosqu rutrum elementum sollicitudin. Vitae metus neque vehicula tempus quisque fermentum iaculis ut, natoque nascetur dis erat tellus ligula eget mi litora, odio parturient lobortis class sollicitudin libero dictumst.

Code:
require('dotenv').config();

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.GUILD_MESSAGES, Intents.GUILD_MESSAGE_REACTIONS, Intents.GUILDS] });



// rest of your code using the client object
const { Collection } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const path = require('path');

// List of all commands
const commands = [];
Client.commands = new Collection();

const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);

    Client.commands.set(command.data.name, command); // Store the command object

    commands.push(command.data.toJSON());
}




// The rest of your code remains the same




Client.once("ready", () => {
    console.log("Client is ready !");
    // Get all ids of the servers
    const guild_ids = client.guilds.cache.map(guild => guild.id);

    const rest = new REST({ version: 9 }).setToken(process.env.TOKEN);

    for (const guildId of guild_ids) {
        rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId), { body: commands })
            .then(() => console.log('Successfully updated command for guid' + guildId))
            .catch(console.error);
    }
});

const client1 = new Client();

client1.on("interactionCreate", async (interaction) => {
    if (!interaction.isCommand()) return;

    const command = client.commands.get(interaction.commandName);

    if (!command) return;

    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: "There was an error executing this command" });
    }
});

client1.login(process.env.TOKEN);

Code:
                                              ^

TypeError: Cannot read properties of undefined (reading 'GUILD_MESSAGES')
    at Object.<anonymous> (C:\Users\osala\Desktop\discord-bot\index.js:4:47)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.14.0`````


ChatGPT , trying different code interpretation

<p>I have this issue with my discord bot code. In this case even ChatGPT won't help. Do you know what the issue could be ? I've tried interpreting the code in other way and asking ChatGPT but none of that helped. Thank you in advance</p>
<p>The stackowerflow requires to add more details but I don't known what to add else so just please ignore this text.</p>
<p>Lorem ipsum dolor sit amet consectetur adipiscing elit arcu parturient hendrerit, tellus metus consequat montes sagittis porttitor dui eros cras, sodales neque ex euismod ac natoque mauris tempor lacinia. Semper est dictum potenti mattis iaculis praesent curabitur non egestas tempor litora, sed luctus ligula facilisis sodales duis maximus conubia orci vel, quis eu eget elit penatibus dis aliquet mi pulvinar facilisi. Ullamcorper lacus gravida ex curabitur parturient nam bibendum ipsum mus, netus tempor commodo justo sociosqu rutrum elementum sollicitudin. Vitae metus neque vehicula tempus quisque fermentum iaculis ut, natoque nascetur dis erat tellus ligula eget mi litora, odio parturient lobortis class sollicitudin libero dictumst.</p>
<pre><code>require('dotenv').config();

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.GUILD_MESSAGES, Intents.GUILD_MESSAGE_REACTIONS, Intents.GUILDS] });



// rest of your code using the client object
const { Collection } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const path = require('path');

// List of all commands
const commands = [];
Client.commands = new Collection();

const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);

Client.commands.set(command.data.name, command); // Store the command object

commands.push(command.data.toJSON());
}




// The rest of your code remains the same




Client.once("ready", () => {
console.log("Client is ready !");
// Get all ids of the servers
const guild_ids = client.guilds.cache.map(guild => guild.id);

const rest = new REST({ version: 9 }).setToken(process.env.TOKEN);

for (const guildId of guild_ids) {
rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId), { body: commands })
.then(() => console.log('Successfully updated command for guid' + guildId))
.catch(console.error);
}
});

const client1 = new Client();

client1.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: "There was an error executing this command" });
}
});

client1.login(process.env.TOKEN);


</code></pre>
<pre><code> ^

TypeError: Cannot read properties of undefined (reading 'GUILD_MESSAGES')
at Object.<anonymous> (C:\Users\osala\Desktop\discord-bot\index.js:4:47)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49

Node.js v20.14.0`````


ChatGPT , trying different code interpretation
</code></pre>
 
Top