简体   繁体   中英

client.guilds only works in the log and not chat

So I was adding a logging feature to my Discord.JS bot and used console.log(client.guilds); and it outputs the guilds and their info in the console, however, if I do message.channel.send(client.guilds) it sends object Object or undefined instead. So my question is how could I make my bot post the contents of client.guilds in the chat?

Guild its a large discord object with many collection. So you can`t send all data to message. But you can get some info and send it. Like this

Discord v12

const Discord = require('discord.js')
const bot = new Discord.Client()
bot.on('message', async message => {
    let clientGuildsData = bot.guilds.cache.map(guild => `${guild.name} - ${guild.id}`).join('\n')
    message.channel.send(clientGuildsData)
})

Discord v11

const Discord = require('discord.js')
const bot = new Discord.Client()
bot.on('message', async message => {
    let clientGuildsData = bot.guilds.map(guild => `${guild.name} - ${guild.id}`).join('\n')
    message.channel.send(clientGuildsData)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM