【发布时间】:2021-03-05 07:58:13
【问题描述】:
目标:我正在努力为不和谐做出丰富的表现。
代码:
const RPC = require("discord-rpc");
const rpc = new RPC.Client({
transport: 'ipc',
});
const chalk = require('chalk');
const settings = require('./settings.json');
const details = settings.details;
const state = settings.state;
const LIK = settings.largeImageKey;
const LIT = settings.largeImageText;
const SIK = settings.smallImageKey;
const SIT = settings.smallImageText;
const ID = settings.clientID;
rpc.on("ready", () => {
rpc.setActivity({
details: `${details}`,
state: `${state}`,
startTimestamp: new Date(),
largeImageKey: `${LIK}`,
largeImageText: `${LIT}`,
smallImageKey: `${SIK}`,
smallImageText: `${SIT}`
});
console.log(chalk.green("Rich Prescence is on: " + rpc.user.username))
});
rpc.login({
clientId: `${ID}`,
})
错误:
(node:2128) UnhandledPromiseRejectionWarning: Error: Could not connect
at Socket.onerror (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\Discord Bots\Testing\Art Prescence\node_modules\discord-rpc\src\transports\ipc.js:32:16)
at Object.onceWrapper (events.js:422:26)
at Socket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:2128) 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)
(node:2128) [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.
它说它没有连接,尽管做的一切都是正确的。我不知道如何解决这个问题。我们将不胜感激。
编辑:注意到我没有包含网站,所以我做了以下操作:
const RPC = require("discord-rpc");
const browser = typeof window !== 'undefined';
const rpc = new RPC.Client({ transport: browser ? "websocket" : "ipc"});
出现同样的错误
【问题讨论】:
-
Discord 开放了吗?
-
没有。我使用不和谐的网站版本。然后我将传输更改为
websocket。这给了我一个错误说UnhandledPromiseRejectionWarning: Error: connection closed at WebSocketTransport.<anonymous> (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\Discord Bots\Testing\Art Prescence\node_modules\discord-rpc\src\client.js:118:16) at Object.onceWrapper (events.js:422:26) at WebSocketTransport.emit (events.js:315:20)... -
尝试使用桌面版
标签: javascript node.js discord discord.js nodes