【发布时间】:2021-01-06 06:25:35
【问题描述】:
我正在开发一个不和谐的机器人,我已经开始不断地出错。控制台日志显示:
2020-09-19T15:19:46.303295+00:00 app[worker.1]: embed.fields[7].value: Could not interpret "{'status': 'online', 'game': {'name': 'pp!help | Connected to 17 servers and 1087 users!', 'type': 1, 'url': 'https://m.youtube.com/watch?v=35XFAkwmU4c'}}" as string.
2020-09-19T15:19:46.303297+00:00 app[worker.1]: at /app/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:68:65
2020-09-19T15:19:46.303299+00:00 app[worker.1]: at /app/node_modules/snekfetch/src/index.js:215:21
2020-09-19T15:19:46.303300+00:00 app[worker.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-09-19T15:19:46.303435+00:00 app[worker.1]: (node:4) 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: 2)
2020-09-19T15:19:46.303522+00:00 app[worker.1]: (node:4) [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
理论上,错误出在我的 bot.js 上的这段代码中,但我找不到:
client.on("ready", () => {
console.log(`Listo, con ${client.users.size} usuarios, en ${client.channels.size} canales de ${client.guilds.size} servidores.`);
client.user.setPresence(
{
status: "online",
game: {
name: `pp!help | Connected to ${client.guilds.size} servers and ${client.users.size} users!`,
url: `https://m.youtube.com/watch?v=35XFAkwmU4c`, // Establece el enlace del juego si el tipo es "STREAMING".
type: "STREAMING"
}
}
);
});
当我尝试运行下一个命令时出现该错误:
const Discord = require('discord.js');
const client = new Discord.Client();
function checkDays(date) {
let now = new Date();
let diff = now.getTime() - date.getTime();
let days = Math.floor(diff / 86400000);
return days + (days == 1 ? " day" : " days") + " ago";
};
let inline = true
let userinfo = {};
userinfo.bot = message.client.user.bot;
userinfo.createdat = message.client.user.createdAt;
userinfo.discrim = message.client.user.discriminator;
userinfo.id = message.client.user.id;
userinfo.mfa = message.client.user.mfaEnabled;
userinfo.pre = message.client.user.premium;
userinfo.presen = message.client.user.presence;
userinfo.tag = message.client.user.tag;
userinfo.uname = message.client.user.username;
userinfo.verified = message.client.user.verified;
userinfo.avatar = message.client.user.avatarURL;
const status = {
false: "No",
true: "Yes"
}
message.channel.send({embed: {
color: 3447003,
author: {
name: userinfo.uname
},
title: userinfo.uname,
description: "Info about this user",
fields: [{
name: "BOT?",
value: userinfo.bot, inline
},
{
name: "Name",
value: userinfo.uname, inline
},
{
name: "Discriminator",
value: `#${userinfo.discrim}`, inline
},
{
name: "Client ID",
value: userinfo.id, inline
},
{
name: "2FA?",
value: userinfo.mfa, inline
},
{
name: "It paid?",
value: userinfo.pre, inline
},
{
name: "Created at",
value: userinfo.createdat, inline
},
{
name: "Presence",
value: userinfo.presen, inline
}
],
timestamp: new Date(),
}
});
}
如果有人能告诉我该日志失败是什么意思或什么,我将非常感谢。
谢谢。
【问题讨论】:
标签: javascript node.js discord discord.js bots