Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Guild is showing undefined discord.js

So I am building my bot using discord.js (v13).

Here is my code:

const { MessageEmbed } = require('discord.js')
const { SlashCommandBuilder } = require("@discordjs/builders")
const guild = require('../config.json');

module.exports = {
data: new SlashCommandBuilder()
    .setName('server')
    .setDescription('Display info about this server.'),

async execute(interaction) {

    const exampleEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle(`Server infomation on ${guild.name}`)
.setDescription('Tells Server Info')
.addFields(
    { name: 'Server Name', value: `${guild.name}` },
    { name: '\u200B', value: '\u200B' },
    { name: 'Inline field titlve', alue: 'Some value here', inline: true },
    { name: 'Inline field title', value: 'Some value here', inline: true },
)
.setTimestamp()

    await interaction.reply({embeds: [exampleEmbed]}) ;
},
};

the above is an example of a slash command with an embed. In my embed, I am trying to print the guild name. Using guild.name. I don't get any error in the terminal but when I run the code in my discord server my bot shows undefined.

What am I doing wrong here and how do I fix it?

Edit: My Config.json:-

{
    "token": "Test Test",
    "clientId": "Client Id",
    "guildId": "Guild Id"
}

P.S. I am kinda new to discord.js and javascript

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is that the variable guild is the content of the config.json file. If this file contains an object with the keys guildID and clientID only, guild.name will be undefined.

I think you want to use the guild where the interaction is coming from, in this case, it's interaction.guild:

async execute(interaction) {
  const exampleEmbed = new MessageEmbed()
    .setColor('#0099ff')
    .setTitle(`Server infomation on ${interaction.guild.name}`)
    .setDescription('Tells Server Info')
    .addFields(
      { name: 'Server Name', value: `${interaction.guild.name}` },
      { name: '\u200B', value: '\u200B' },
      { name: 'Inline field title', value: 'Some value here', inline: true },
      { name: 'Inline field title', value: 'Some value here', inline: true },
    )
    .setTimestamp();

  await interaction.reply({ embeds: [exampleEmbed] });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda