Discord bot embed issue

I’m working on a Discord bot using v14 and I’ve run into a problem with my code. Here’s what I’m trying to do:

const embed = new EmbedBuilder(interaction.message.embeds[0])
  .setColor(0x00FF00)
  .setFooter({
    text: botClient.username
  });

interaction.message.edit({
  embeds: [embed],
  components: []
});

const memberInfo = interaction.guild.members.cache.find(
  member => member.user.tag === botClient.username
);

But I keep getting this error:

TypeError: Cannot read properties of undefined (reading 'find')

I’m not sure what I’m doing wrong. Can anyone help me figure out why this is happening and how to fix it? I’ve been stuck on this for a while and any advice would be really helpful. Thanks!

I’ve run into this issue before, and it can be frustrating. One thing that worked for me was using the .fetch() method on the guild members before trying to access the cache. Something like this:

await interaction.guild.members.fetch();

This ensures all members are loaded before you try to find a specific one. Also, double-check your intents. I wasted hours once because I forgot to enable the right intents in both my code and the Discord developer portal.

If that doesn’t work, try logging interaction.guild to make sure it’s not null. Sometimes the guild object isn’t available right away, especially in larger servers. You might need to add a short delay or check guild.available first.

Hope this helps! Let us know if you get it working.

Have u checked if the guild is available? sometimes it takes a bit to load. try adding a delay or using guild.available before fetching members. also make sure ur bots intents are set up right in the discord dev portal. those can be tricky

The error you’re encountering suggests that interaction.guild.members.cache is undefined. This could happen if the bot doesn’t have the necessary permissions or if the guild members haven’t been cached.

Try fetching the members before accessing the cache:

await interaction.guild.members.fetch();
const memberInfo = interaction.guild.members.cache.find(
  member => member.user.tag === botClient.username
);

Also, ensure your bot has the ‘Guild Members Intent’ enabled in the Discord Developer Portal and in your bot’s initialization code. This intent is required to access member information.

If the issue persists, double-check that interaction.guild is not null and that botClient.username is correctly defined. Logging these values might help pinpoint the problem.