Type error: cannot read properties of undefined

const { Client, Intents, MessageEmbed } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { SlashCommandBuilder } = require('@discordjs/builders');

const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
// Add the necessary intent for GUILD_COMMANDS
Intents.FLAGS.GUILD_MESSAGE_CONTENT,
],
});

const token = 'YOUR_BOT_TOKEN'; // Replace with your bot token
const clientId = 'YOUR_CLIENT_ID'; // Replace with your bot's client ID

const commands = [
new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with latency information'),
].map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

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

try {
console.log('Started refreshing global (/) commands.');

await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log('Successfully reloaded global (/) commands.');
} catch (error) {
console.error(error);
}
});

client.on('messageCreate', async message => {
if (message.content === '/ping') {
const botLatency = Date.now() - message.createdTimestamp;
const embed = new MessageEmbed()
.setTitle('/ping')
.setDescription(`Bot Latency: ${botLatency}ms\nWebSocket latency: ${client.ws.ping}ms`)
.setFooter(`${client.user.username}`, client.user.avatarURL());

try {
await message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
}
}
});

client.login(token);
const { Client, Intents, MessageEmbed } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { SlashCommandBuilder } = require('@discordjs/builders');

const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
// Add the necessary intent for GUILD_COMMANDS
Intents.FLAGS.GUILD_MESSAGE_CONTENT,
],
});

const token = 'YOUR_BOT_TOKEN'; // Replace with your bot token
const clientId = 'YOUR_CLIENT_ID'; // Replace with your bot's client ID

const commands = [
new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with latency information'),
].map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

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

try {
console.log('Started refreshing global (/) commands.');

await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log('Successfully reloaded global (/) commands.');
} catch (error) {
console.error(error);
}
});

client.on('messageCreate', async message => {
if (message.content === '/ping') {
const botLatency = Date.now() - message.createdTimestamp;
const embed = new MessageEmbed()
.setTitle('/ping')
.setDescription(`Bot Latency: ${botLatency}ms\nWebSocket latency: ${client.ws.ping}ms`)
.setFooter(`${client.user.username}`, client.user.avatarURL());

try {
await message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
}
}
});

client.login(token);
2 Replies
d.js toolkit
d.js toolkit16mo 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!
gamer50082
gamer50082OP16mo ago
const { Client, GatewayIntentBits, MessageEmbed } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { SlashCommandBuilder } = require('@discordjs/builders');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageContent,
],
});

const token = 'YOUR_BOT_TOKEN'; // Replace with your bot token
const clientId = 'YOUR_CLIENT_ID'; // Replace with your bot's client ID

const commands = [
new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with latency information'),
].map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

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

try {
console.log('Started refreshing global (/) commands.');

await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log('Successfully reloaded global (/) commands.');
} catch (error) {
console.error(error);
}
});

client.on('messageCreate', async message => {
if (message.content === '/ping') {
const botLatency = Date.now() - message.createdTimestamp;
const embed = new MessageEmbed()
.setTitle('/ping')
.setDescription(`Bot Latency: ${botLatency}ms\nWebSocket latency: ${client.ws.ping}ms`)
.setFooter(`${client.user.username}`, client.user.avatarURL());

try {
await message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
}
}
});

client.login(token);
const { Client, GatewayIntentBits, MessageEmbed } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { SlashCommandBuilder } = require('@discordjs/builders');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageContent,
],
});

const token = 'YOUR_BOT_TOKEN'; // Replace with your bot token
const clientId = 'YOUR_CLIENT_ID'; // Replace with your bot's client ID

const commands = [
new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with latency information'),
].map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

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

try {
console.log('Started refreshing global (/) commands.');

await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log('Successfully reloaded global (/) commands.');
} catch (error) {
console.error(error);
}
});

client.on('messageCreate', async message => {
if (message.content === '/ping') {
const botLatency = Date.now() - message.createdTimestamp;
const embed = new MessageEmbed()
.setTitle('/ping')
.setDescription(`Bot Latency: ${botLatency}ms\nWebSocket latency: ${client.ws.ping}ms`)
.setFooter(`${client.user.username}`, client.user.avatarURL());

try {
await message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
}
}
});

client.login(token);
bitfieldinvalid
Want results from more Discord servers?
Add your server