discord.js - 启动时显示 discord 公会 id 和公会名称
问题描述
我不想问是否可以列出我的机器人在加载时所在的所有不和谐公会 ID 和名称..?
I need to check if there are any ghost servers..
解决方案
是的,你可以使用这个:
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');
推荐阅读
- c# - C# 插值字符串中的变量求值顺序
- haskell - 使用 Servant 根据 `Maybe` 的内容回答 200 或 404 的请求
- visual-studio-code - 创建兼容 ssh 的 vscode 扩展
- jquery - 按钮只允许点击一次
- python - 一个视图中的 Django 多个 GET 请求
- c - 可以用光线追踪器渲染莫比乌斯带吗?
- signals - Simulink,生成多项式输入信号
- mongodb - 如何将 mogodb 中的数据分组并将两个字段合并为一个字段?
- arrays - 如何使用 Flutter 中的数组按文档 ID 搜索 Firestore 集合
- javascript - Firefox 的检查元素如何确定 HTML 元素的查询选择器?