簡體   English   中英

我對 discord.js rpc 有錯誤? 有人可以幫幫我嗎?

[英]I have an error for discord.js rpc! Can someone please help me?

這是我的錯誤:

(node:42087) UnhandledPromiseRejectionWarning: Error: Could not connect
    at Socket.onerror (/Users/vinesh/RPC/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:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:42087) 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:42087) [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 client = new RPC.Client({ transport: 'ipc' });
client.on('ready', () =>
{
    client.request('SET_ACTIVITY', {
        pid: process.pid,
        activity: {
            assets: {
                large_image: 'Coding'
            },
            details: 'Coding',
            buttons: [
                { label: 'Emperor', url: 'https://dsc.gg/invite-emperor' },
                { label: 'https://dsc.gg/invite-emperor', url: 'https://dsc.gg/invite-emperor' }
            ]
        }
    });
    console.log('started!');
});
client.login({ clientId: 'My_ID' });

我該如何解決? 是不是因為代碼太舊了? 我不知道為什么會這樣。 我做了npm init -ynpm install discordnpm install discord-rpc

如果您運行的是 Discord 的 web 瀏覽器版本,則 RPC 將不起作用。 而是下載 Discord 桌面版,這里是。

如果您正在運行 Discord 桌面,請嘗試此代碼。 還記得在https://discord.com/developers/applications/Application_ID/rich-presence/assets中添加您的資產,並確保它們在應用程序和代碼中的名稱相同。 你需要large_text所以不要刪除它。

var rpc = require("discord-rpc")
const client = new rpc.Client({ transport: 'ipc' })
client.on('ready', () => {
    client.request('SET_ACTIVITY', {
        pid: process.pid,
        activity : {
            details : "Coding",
            assets : {
                large_image : "Your Image",
                large_text : "Your Status"
            },
            buttons : [{label : "Emperor" , url : "https://dsc.gg/invite-emperor"},{label : "Invite 2?",url : "https://dsc.gg/invite-emperor"}]
        }
    })
})
client.login({ clientId : "CLIENT_ID" }).catch(console.error);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM