[英]My code for Discord.JS is having a strange error, can you please help me solve this?
[英]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 -y
, npm install discord
和npm 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.