本文介绍了使用 Discord.js 获取所有公会 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
所以我想从我的机器人所在的服务器上获取每个 ID.请以最好的方式列在一个列表中,这样我就可以一个接一个地获得一个 ID,因为我的前缀系统需要它们.我尝试了很多设计,但都无法正常工作.
So I want to get every ID from the servers my bot is on. In the best way please in a list so I could get one ID after another because I need them for my prefix system. I tried a lot of designs but it didn't work right.
推荐答案
你可以使用 Collection#map
映射 Client.guilds.cache
(GuildManager#cache
) 按 ID.
You can use Collection#map
to map Client.guilds.cache
(GuildManager#cache
) by ID.
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
const Guilds = client.guilds.cache.map(guild => guild.id);
console.log(Guilds);
});
client.login(process.env.DISCORD_ACCESS_TOKEN)
Discord JS V13
const Discord = require("discord.js");
const client = new Discord.Client({
intents: ["GUILDS"],
});
client.on("ready", () => {
const Guilds = client.guilds.cache.map(guild => guild.id);
console.log(Guilds);
});
client.login(process.env.DISCORD_ACCESS_TOKEN);
这篇关于使用 Discord.js 获取所有公会 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!