1 回答
TA贡献1875条经验 获得超3个赞
这是因为在您尝试获取的第 6 行,您尚未登录。您bot.login()
稍后会调用(并且它是异步的)
const guild = bot.guilds.fetch('222078108977594368')
如果您只想获取一次,您可以将其移至ready
状态处理程序:
const Discord = require('discord.js')
const { send, stdout } = require('process')
const bot = new Discord.Client()
const token = 'XXX'
const prefix = 'a!'
// use let, so you can change it later in bot.on('ready')
let guild = null
// this event will only trigger after logging in
bot.on('ready', () => {
const ping = new Date()
// fetch here
guild = bot.guilds.fetch('222078108977594368')
ping.setHours(ping.getHours() - 3)
console.log(`BOT INICIADO AS ${ping.getUTCHours()}:${ping.getUTCMinutes()}:${ping.getUTCSeconds()}`)
console.log('GuruGuru Está Online!')
bot.user.setActivity(`${bot.guilds.cache.size} servidores`, { type: 'WATCHING' });
})
添加回答
举报