-1

I'm trying to make a Discord bot send all of the server owner's ids and usernames in one embed. This is my current code:

else if (command === '!test'){
        const owners = client.guilds.cache.forEach(guild => console.log('<@' + guild.ownerID + '>'));
        const owners1 = JSON.stringify(owners)

        const embed = new Discord.MessageEmbed()
                .setColor('#fc2eff')
                .setTitle('Owners who added bartt')
                .setDescription(owners1)
                .setTimestamp();
        
            msg.channel.send(embed);
}

it logs the ids to console which is what I need but I want to show them in an embed not just console.

I'd rather log Discord names and not ids purely for the fact Discord doesn't always show users from their id.

Pxndaaa
  • 13
  • 4

2 Answers2

0

Use Iterable#map() to create an array of all the ID concatenations, then use Array#join() to join the array into a single string. Use this string in the embed.

const ownersArray = client.guilds.cache.map(guild => `<@${guild.ownerID}>`);

const embed = new Discord.MessageEmbed()
    .setColor('#fc2eff')
    .setTitle('Owners who added bartt')
    .setDescription(ownersArray.join(',\n'))
    .setTimestamp();
        
msg.channel.send(embed);
Elitezen
  • 6,551
  • 6
  • 15
  • 29
0

If you want to get the owners username you can try this:

const { username } = await message.client.users.fetch(message.guild.ownerID);

// Optional, you can also use the 'username' variable
const serverOwner = username;

Keep in mind that you have to make your execute method async.

You could also use the guilds cache but this only worked for me if the owner was online. If he went offline he wasn't cached anymore and I just got an error

I don't know what you mean by multiple owners, since there is only one, the one who created the server

Toasty
  • 1,850
  • 1
  • 6
  • 21