Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!