我的命令加载器不工作。基本上,它应该从文件夹中加载所有的.js文件。/命令/信息它所做的是,它说它已经加载好了,准备好了,但是机器人不会在不和谐的情况下上网。我试着改变标记,重新混合项目,甚至遍历代码,但是没有什么效果。我正在glitch.me上托管它。
const express = require("express");
const app = express();
// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));
// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
response.sendFile(__dirname + "/views/index.html");
});
// listen for requests :)
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port + "\nBot is now ready!");
});
// LOAD COMMANDS
const { Client, Collection, Attachment } = require("discord.js");
const { config } = require("dotenv");
const discord = require("discord.js");
const client = new discord.Client();
// Collections
client.commands = new Collection();
client.aliases = new Collection();
config({
path: __dirname + "/.env"
});
// Run the command loader
["command"].forEach(handler => {
require(`./handlers/${handler}`)(client);
});
client.on('ready', () => {
var guilds = [];
client.guilds.cache.array().forEach( (guild) =>{
guilds.push(guild.name);
});
client.on('ready', () => {
var guilds = [];
client.guilds.cache.array().forEach( (guild) =>{
guilds.push(guild.name);
});
if(guilds.length > 0){
console.log("Servers:");
console.log(guilds.join("\n"));
console.log();
}
})
const prefix = "*";
client.on('message', async (message) => {
if (message.author.bot) return;
if (!message.guild) return;
if (!message.content.startsWith(prefix)) return;
// If message.member is uncached, cache it.
if (!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
// Get the command
let command = client.commands.get(cmd);
// If none is found, try to find it by alias
if (!command) command = client.commands.get(client.aliases.get(cmd));
// If a command is finally found, run the command
if (command)
command.run(client, message, args);
});
// -----
client.login(process.env.SECRET);
})任何帮助都是非常有用的,注意:它没有说任何错误,它只是没有在线
发布于 2020-06-19 14:59:50
问题出在这里。
您正在将所有代码放入client.on('ready')函数中。
看到})后面的client.login了吗?把})放在guilds.push()后面。
由于client.login处于就绪事件中,所以在它准备好后尝试登录,这是不可能的。
https://stackoverflow.com/questions/62471547
复制相似问题