While making a Discord Bot, it shows 0 when client guilds cache size is used in the info command. in the chat it looks like this
const { DiscordAPIError, MessageEmbed } = require("discord.js");
const config = require("../config.json");
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = config.prefix;
module.exports = {
name: 'info',
description: "info",
execute(message, args, Discord) {
const newEmbed = new MessageEmbed()
.setColor('RANDOM')
.setFooter('Info for Laughing Horse 🤖')
.addFields(
{name: 'Bot tag', value: '`Laughing Horse#6722`'},
{name: 'Version', value: '`1.0.4`'},
{name: 'Prefix', value: prefix},
{name: 'Bot Dev', value: '`Skep#2721`'},
{name: 'server count', value: `the bot is currently in ${client.guilds.cache.size} servers`}
)
message.channel.send(newEmbed);
}
}
As said in the comment, client.guilds.cache.size
is returning 0 because your creating a new client in this folder but this client never logs in to discord so hence 0 guilds loaded
const client = require(your index file);
don't work as your not exporting client from index.js or anything like that,
As this is a command and you seem to be passing message from message event
execute(message, args, Discord)
You can do message.client.guilds.cache.size
Hopes this helps
ps: Your doing Discord
in the execute function and also requiring it at the top, const Discord =...
you should remove one of these
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.