gpt4 book ai didi

javascript - Discord Rich Presence 未连接

转载 作者:行者123 更新时间:2023-12-05 04:56:19 26 4
gpt4 key购买 nike

目标:我正在努力为 discord 做一个丰富的存在。

代码:

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"});

出现同样的错误

最佳答案

作为@mark-oe说明,您必须运行桌面版的 Discord 才能让 RPC 连接到 WSS (WebSockets)

关于javascript - Discord Rich Presence 未连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64954252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com