0

My bot is in 20+ servers and I want to be able to show users the servers my bot is in. I was able to do this on my own but i want the list of servers in one embed and if it passes the embed character limit a page 2 of the embed.

Code:

    if (message.content === 'zservers'){
        bot.guilds.cache.forEach((guild) => {
            const serverlist = new Discord.MessageEmbed()
            .setTitle(`   .`)
            .addField(guild)
            .setFooter(`Invite lovell <$`)
            message.channel.send(serverlist)
        })
    }

Result:

enter image description here

I want to be able to list all servers in a single embed!

  • Maybe this helps - https://discordjs.guide/popular-topics/embeds.html#embed-limits. If you don't wanna go through it all, The overall gist is, you can have up to 25 fields in an embed and 1 embed per message. So you can make fields and messages accordingly. – Saurav Sep 27 '20 at 14:35
  • I won't do this as you simply can get ratelimited really fast for sending too many messages after each other – node_modules Sep 27 '20 at 17:06
  • That's why I want it in one embed only ! –  Sep 29 '20 at 05:36

3 Answers3

1

this should work

if (message.content === 'zservers'){
        let serverlist = ''
        bot.guilds.cache.forEach((guild) => {
            serverlist = serverlist.concat(" - " + guild.name + ": ID: " + guild.id + "\n")
        })
    
        const embed = new MessageEmbed()
        .setColor("RANDOM")
        .setTitle("Servers that have Naruse Jun Bot", '')
        .setDescription(serverlist)
        message.channel.send({embed});

}
RealPenguin
  • 89
  • 1
  • 5
0

Make a general string and then append the guilds to this string.

    if (message.content === 'zservers'){
        let guilds = '';
        bot.guilds.cache.forEach((guild) => {
            guilds = guilds.concat(guild).concat("\n"); // concatenate the guild and add a new line in the end.
        })
        const serverlist = new Discord.MessageEmbed()
        .setTitle(`   .`)
        .addField(guilds) // use the general 'guilds' string.
        .setFooter(`Invite lovell <$`)
        message.channel.send(serverlist)
    }
Nikolas
  • 49
  • 3
  • It gave me this error : `(node:11896) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.fields[0].name: Must be 256 or fewer in length.` I think it's because there is too much. I'm not quite sure how to fix this though. I'm quite new to this. –  Sep 27 '20 at 14:39
  • 1
    You can use [`Util#splitMessage`](https://discord.js.org/#/docs/main/stable/class/Util?scrollTo=s-splitMessage). – Jakye Sep 27 '20 at 15:00
  • 1
    Also instead of using `concat()` you could just use `map()` – Lioness100 Sep 27 '20 at 15:05
  • It's `guilds = guilds.concat(guild.name).concat("\n");` no? – Dylan Delobel Mar 07 '23 at 10:05
0

Work?

Edit: UPDATED! Should work now.

if (message.content === 'zservers'){
    let guilds = bot.guilds.cache.array().join('\n')

    const serverlist = new Discord.MessageEmbed()
      .setTitle(`   .`)
      .setDescription(guilds)
      .setFooter(`Invite lovell <$`)

    message.channel.send(serverlist)
}

Edit 2: Similar question and exactly right answer -> https://stackoverflow.com/a/60693028/7090121

Berk Ege
  • 86
  • 6
  • It said ".join() is not a function" so i figured to put .array() function instead and it worked. Thank you so much for your contribution. –  Sep 29 '20 at 21:33
  • Thx for to information. I updated my code. But looks like u find your answer. Anyway you should check link I given you. There also paging system. – Berk Ege Sep 30 '20 at 13:20