我的命令加载器不起作用。 基本上,它应该从文件夹./commands/info加载所有.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);
})
任何帮助将不胜枚举 注意:它不会说任何错误,只是不会在线
答案 0 :(得分:0)
这是问题所在。
您要将所有代码放入function load_more_posts() {
$next_page = $_POST['current_page'] + 1;
$query = new WP_Query([
'posts_per_page' => 12,
'paged' => $next_page
]);
if ($query->have_posts()):
ob_start();
while($query->have_posts()) : $query->the_post();
get_template_parts('partials/blog','posts');
endwhile;
wp_send_json_success(ob_get_clean());
else:
wp_send_json_error('no more posts');
endif;
wp_die();
}
函数中。
看到client.on('ready')
之后的})
吗?将client.login
放在})
之后。
由于client.login处于ready事件中,因此您试图在它准备就绪后登录,这是不可能的。