【发布时间】:2021-10-20 00:39:40
【问题描述】:
我一直在尝试使用文档here 中提到的语法来获取我的公会中所有成员的列表。但我没有收到任何输出。下面是我正在使用的代码。
const { Client, Intents, Guild } = require("discord.js");
require("dotenv").config();
const commandHandler = require("./commands");
const fetch = require("node-fetch");
const client = new Client({
intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_PRESENCES"],
});
client.once("ready", async (data) => {
console.log("Ready!");
console.log(`Logged in as ${client.user.tag}!`);
const Guilds = client.guilds.cache.map((guild) => guild);
console.log(Guilds[0]);
await Guilds[0].members.fetch().then(console.log).catch(console.error);
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === "ping") {
await interaction.reply(client.user + "????");
}
});
client.on("messageCreate", commandHandler);
client.login(process.env.BOT_TOKEN); // Kushagra's bot
我正在通过第 13 行的 console.log 获取有关 Guild 实例的信息。但是第 15 行没有得到任何输出。
但是,我注意到如果我在第 14 行向fetch() 命令添加选项,我会得到一些输出。当我添加{query: 'random text'} 时,我收到了一些输出。
只是想了解为什么我无法获得所有成员的列表。 谢谢!????
【问题讨论】:
标签: javascript node.js discord discord.js