[英]UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require("fs");
const config = require('./config.json');
const prefix = config.prefix;
const glois = JSON.parse(fs.readFileSync("global.json", "utf8"));
const escapeRegex = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
client.on('ready', () => {
console.log(`${client.user.username} is ready`);
const activities_list = [({ activity: { name: `${client.guilds.cache.reduce((a, b) => a + b.memberCount, 0).toLocaleString()} Usern auf ${client.guilds.cache.size} Servern zu` }, status: 'online' }), ({ activity: { name: `${prefix} | Kanax in Discord 💙` }, status: 'online' })]
setInterval(() => {
const index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
client.user.setPresence(activities_list[index]);
}, 15000); // Runs this every 15 seconds.
})
client.on("message", async message => {
if (message.author.bot) return;
const sender = message.author;
const channelmtn = message.mentions.channels.first()
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`);
if (!prefixRegex.test(message.content)) return;
const [, matchedPrefix] = message.content.match(prefixRegex);
const args = message.content.slice(matchedPrefix.length).trim(/ +/g);
const cmd = args.toLowerCase().split();
if(cmd == "ping") {
let Pong = "Pong!"
var ping = Date.now() - message.createdTimestamp;
let pembed = new Discord.MessageEmbed()
.setTitle(client.user.username + "'s Ping")
.setDescription(`:hourglass: **Latency**\n${ping}ms\n:heartbeat: **API**\n${client.ws.ping}ms`)
.setColor("#00ffff")
await message.channel.send('Pingen...').catch(console.error)
.then(async message => {
setTimeout(() => { message.edit(Pong); }, 2000);
setTimeout(() => { message.edit(pembed); }, 2000);
})
};
if (cmd == "invite") {
let invembed = new Discord.MessageEmbed()
.setTitle("Du kannst mich hier einladen")
.setURL("https://discord.com/api/oauth2/authorize?client_id=711620266492690474&permissions=537390145&scope=bot")
.setColor("#00ffff")
message.channel.send(invembed)
};
if(cmd == "stop")
if (message.author.id === "602935358316871709") {
console.log(`${sender.username} (${sender.id}) hat den Bot gestoppt`)
message.channel.send(`<@${sender.id}> hat den Bot gestoppt`)
process.exit();
}
if(message.content.startsWith(prefix + "set global")) {
if(!channelmtn) return message.reply("Erwähne einen Textchannel!")
glois[message.guild.id] = {
globalchat: channelmtn.id
};
fs.writeFile("global.json", JSON.stringify(glois), err => {
if (err) console.log(err);
});
let setembed = new Discord.MessageEmbed()
.setTitle("Setup")
.setDescription(`Der Globalchat wurde zu <#${channelmtn.id}> gesetzt`)
message.channel.send(setembed);
};
const sett = JSON.parse(fs.readFileSync("global.json", "utf8"));
if (!sett[message.guild.id]) {
sett[message.guild.id] = {
globalchat: "698616682452746281"
};
}
const globis = sett[message.guild.id].globalchat;
if(message.channel.id === globis) {
const embed = new Discord.MessageEmbed()
.setTitle(message.author.tag)
.setDescription(message.content)
.setThumbnail(message.author.avatarURL)
.setColor("#000000")
.setFooter(`Coming soon`)
client.guilds.cache.forEach(guild => {
try{
client.channels.cache.get(glois[message.guild.id].globalchat).send(embed)
} catch(error) {
console.error(error)
}
});
};
});
client.login(config.Token)
If I send gk!set global #test
then in the console will stay this如果我发送
gk!set global #test
那么在控制台中将保持这个
(node:8216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
warning.js:32
(node:8216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
It simply means your JSON isn't valid JSON.这只是意味着您的 JSON 无效 JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.