首页 > 解决方案 > 启动时显示 discord 公会 id 和公会名称

问题描述

我不想问是否可以列出我的机器人在加载时所在的所有不和谐公会 ID 和名称..?

I need to check if there are any ghost servers..

标签: discord.js

解决方案


是的,你可以使用这个:

client.guilds.cache.map(r => `${r.name} - ${r.id}`);

完整示例:

//Define client and discord
const Discord = require('discord.js');
const client = New Discord.Client();

//When the client is ready, print all guilds
client.on('ready', () => {
    console.log(client.guilds.cache.map(r => `${r.name} - ${r.id}`));
});

//Login the client
client.log('your-secret-token');

推荐阅读