Is there a way to obtain the specific guild ID from the ready event?

I am currently working on making this bot function across multiple servers, and I need to retrieve a specific guild ID similar to using message.guild.id. However, since there is no message defined or declared, I am unsure of how to achieve this. Any suggestions?

Thank you

Here is the code snippet:

const db = require(`quick.db`)
let cid;
const { prefix } = config

client.on('ready', async () => {


  console.log(`${client.user.tag} is online`);
  console.log(`${client.guilds.cache.size} Servers`);
  console.log(`Server Names:\n[ ${client.guilds.cache.map(g => g.name).join(", \n ")} ]`);


  loadCommands(client)
  
  
 


cron.schedule('*/10 * * * * *', () => {
    const zkrRandom = zkrList[Math.floor(Math.random() * zkrList.length)]
    const zkrEmbed = new Discord.MessageEmbed()


      .setDescription(zkrRandom)
      .setAuthor('xx', logo)
      .setColor('#447a88')




    client.channels.cache.get(cid).send(zkrEmbed);
  })

  
})


client.login(config.token)

The error I encountered:

cid = db.get(`${message.guild.id}_channel_`)
                  ^

ReferenceError: message is not defined

Answer №1

Store guild names and IDs in the data storage section under guilds.cache. This allows you to easily retrieve a list of all the guilds your bot has joined. By simply changing name to id, you can obtain an array of all the guild IDs that the bot is part of.

console.log(client.guilds.cache.map(guild => guild.id)) // ['1234567890', '0987654321']

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Rendering views and templates in Node.js using EJS

I have a couple of queries regarding the render view functionality, Why does it not work as expected? When I place res.render inside if(error), the new site is not rendered and it remains on the current page. Another question I have is related to displayi ...

What is the proper way to import route modules in Express?

After using express-generator to create a project, I ended up with two files in my routes directory: index.js and users.js. Additionally, there was a file named about.js which was responsible for handling the /about route. However, when attempting to acce ...

Communicating between a Python Client and a nodeJS Server using Socket.IO

I am attempting to transmit data from my Raspberry Pi (using Python 2.7.9) to my NodeJS server with socket.io. My objective is to continuously send multiple values from my Pi through a websocket connection to my local Node Server, which will then display ...

Transitioning Node JS code to Apollo server

Currently, I am in the process of configuring Apollo Server on my Node application and contemplating transferring the functionality over to Apollo. The current business logic I have looks like this: router.post( '/login', (req, res, nex ...

Is it possible to use function declaration and function expression interchangeably?

As I dive into learning about functions in Javascript, one thing that's causing confusion for me is the difference between function declaration and function expression. For example, if we take a look at this code snippet: function callFunction(fn) { ...

Tips on parsing a CSV file from a Node/Express Axios GET request?

I am currently working on a Node/Express backend that utilizes axios to send a GET request to the following URL: https://marknadssok.fi.se/Publiceringsklient/sv-SE/Search/Search?SearchFunctionType=Insyn&Utgivare=&PersonILedandeSt%C3%A4llningNamn=&a ...

Can I divide certain parts of my template and store them in separate files?

I want to separate the navigation part of my Jade template into a different file called 'navigation.jade'. Is it possible to do that? Currently, I have layout.jade and I would like to achieve something like this: mixin ie(condition, content) ...

The system does not recognize NODE_ENV as a valid command

As I delve into the world of node.js development, I'm taking steps to ensure my code works seamlessly in both production and development environments. After some research, I discovered that setting NODE_ENV while running the node.js server achieves th ...

Error: Can const be used in strict mode?

Currently, I am attempting to log in to facebook.com using selenium-webdriver. var webdriver = require('selenium-webdriver'), By = require('selenium-webdriver').By, until = require('selenium-webdriver').until; var dr ...

Utilizing ES6 promises in node.js to send a null response

I'm looking for assistance on how to execute a query using ES6 native promises in node.js. The code I have below is what I've been working with: let arr= []; conn.query('select * from table1', (err, b) => { for (let i = 0; i ...

Has Jade stopped allowing inline variables unless enclosed by JavaScript markers?

Back when I was using Jade version 0.34.1 (prior to the release of version 1.0.0), I had the ability to incorporate inline variables like this: test = 'fun' p #{test} This would typically result in: <p>fun</p> However, the output ...

dynamic query approach for MongoDB with Express and NodeJs

Currently, I am developing an API using MongoDB, Express, and Node.js. So far, my progress has been good as I am able to query for a single record by ID, search for a specific field, delete, add, and more. However, I am now in search of a method that can ...

Encountering a problem with the node.js version while trying to install

Currently in the process of setting up my Raspberry Pi as a node.js server. Recently performed a clean installation of Raspberian Subsequently, I installed node Upon running node -v, the system displays: v0.10.25 Proceeded to install npm When checking ...

Trouble with Mongoose adding items to an array

ReviewSchema with Mongoose: import mongoose from "mongoose"; const ReviewSchema = new mongoose.Schema({ likes: { type: Number, required: true, default: 0, }, reactedBy: [ { required: true, ...

Run code following the receipt of two responses from API calls

Greetings! Currently, I am in the process of making two separate API calls for validation checks. My goal is to have code executed only after both calls have been successfully completed. var firstCall = request.get('/first', function (error, res ...

Retrieve all items from DynamoDB using a list of specified IDs

I am working with a table that has an attribute named id of type HASH. My goal is to retrieve all items from an array of ids. { TableName: `MyTable`, FilterExpression: 'id IN (:id)', ExpressionAttributeValues: { ':id': ids ...

`Error: <projectname> is currently experiencing issues``

I recently globally installed express by running the command npm install -g express-generator@4 However, when I try to create a new project using the command 'express .', nothing happens. There are no errors displayed either. What could be caus ...

What is the best way to execute two queries and get back two objects in my route request?

I am interested in incorporating a second query call (using Mongoose for MongoDB) and returning the object in the same manner as I currently do with my Car object. Is there a method to execute the second query within the router so that both objects can b ...

Is it possible to determine the number of lost volatile messages in Node.js when using Socket.IO?

I have been looking into this topic and couldn't find any information regarding this specific problem. I am working on a project that utilizes Socket.IO in Node.js. My inquiry is straightforward: Is there a method to determine the number of messages ...

The node.js and express.js update operation (CRUD) is not rendering the CSS files properly

I am currently developing a CRUD app using Node.js/Express.js with EJS as the templating engine. The concept I'm working on involves displaying user_ids from a database, and when an admin clicks on a user_id, it should redirect them to the edit_team. ...