Client.roles.cache.size =>未定义| Discord.js v12

时间:2020-08-05 20:25:57

标签: javascript node.js discord.js

// LoRaFi receiving data using interrupt #include <LoRaFi.h> //creat object to call functions of LoRaFi library LoRaFi LoRaFi; const int messageLength = 11; char message[messageLength]; void setup() { //initialize serial communication Serial.begin(9600); delay(100); //initialize LoRa module LoRaFi.begin(); delay(100); // activate the interrupt on LoRaFi receiving LoRaFi.ReceivingInterrupt(receiveMessage); } void loop() { //Just waiting the interrupt and do nothing delay(1000); } //callback function to receve the temperature and humidity using interrupt routine void receiveMessage() { Serial.print("Received Message: "); //Receive message LoRaFi.ReceivePackage(message,messageLength); //Print received message int i; for(i=0; i<messageLength; i++) { Serial.print(message[i]); } Serial.println(); } 在v12中似乎不适用于我,只是说client.roles.cache.size未定义

是否有其他方法可以获取机器人当前在所有行会中实例化的角色的总数

1 个答案:

答案 0 :(得分:3)

Client没有名为roles的属性。此属性属于Guild


您可以通过roles.cache.size映射公会并获取数组的总和。

const roles = client.guilds.cache.map(guild => guild.roles.cache.size);
console.log(`Total Roles: ${roles.reduce((a, b) => a + b, 0)}`);