显示嵌入中有多少服务器 bot | Discord.js

我的机器人在 20 多台服务器中,我希望能够向用户显示我的机器人所在的服务器。我自己可以做到这一点,但我想要一个嵌入的服务器列表,如果它通过了嵌入字符限制嵌入的第 2 页。


代码:


    if (message.content === 'zservers'){

        bot.guilds.cache.forEach((guild) => {

            const serverlist = new Discord.MessageEmbed()

            .setTitle(`𝘚𝘦𝘳𝘷𝘦𝘳𝘴 𝘭𝘰𝘷𝘦𝘭𝘭 𝘪𝘴 𝘪𝘯.`)

            .addField(guild)

            .setFooter(`Invite lovell <$`)

            message.channel.send(serverlist)

        })

    }

结果:

http://img.mukewang.com/6427e3000001dc8204520887.jpg

我希望能够在单个嵌入中列出所有服务器!



繁花不似锦
浏览 120回答 3
3回答

HUH函数

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

湖上湖

制作一个通用字符串,然后将公会附加到该字符串。&nbsp; &nbsp; if (message.content === 'zservers'){&nbsp; &nbsp; &nbsp; &nbsp; let guilds = '';&nbsp; &nbsp; &nbsp; &nbsp; bot.guilds.cache.forEach((guild) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; guilds = guilds.concat(guild).concat("\n"); // concatenate the guild and add a new line in the end.&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; const serverlist = new Discord.MessageEmbed()&nbsp; &nbsp; &nbsp; &nbsp; .setTitle(`𝘚𝘦𝘳𝘷𝘦𝘳𝘴 𝘭𝘰𝘷𝘦𝘭𝘭 𝘪𝘴 𝘪𝘯.`)&nbsp; &nbsp; &nbsp; &nbsp; .addField(guilds) // use the general 'guilds' string.&nbsp; &nbsp; &nbsp; &nbsp; .setFooter(`Invite lovell <$`)&nbsp; &nbsp; &nbsp; &nbsp; message.channel.send(serverlist)&nbsp; &nbsp; }

繁花如伊

工作?编辑:更新!现在应该工作了。if (message.content === 'zservers'){&nbsp; &nbsp; let guilds = bot.guilds.cache.array().join('\n')&nbsp; &nbsp; const serverlist = new Discord.MessageEmbed()&nbsp; &nbsp; &nbsp; .setTitle(`𝘚𝘦𝘳𝘷𝘦𝘳𝘴 𝘭𝘰𝘷𝘦𝘭𝘭 𝘪𝘴 𝘪𝘯.`)&nbsp; &nbsp; &nbsp; .setDescription(guilds)&nbsp; &nbsp; &nbsp; .setFooter(`Invite lovell <$`)&nbsp; &nbsp; message.channel.send(serverlist)}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript