th-ch / youtube-music

YouTube Music Desktop App bundled with custom plugins (and built-in ad blocker / downloader)
https://th-ch.github.io/youtube-music/
MIT License
8.99k stars 512 forks source link

[Bug] Discord Plugin Failing #208

Closed Araxeus closed 3 years ago

Araxeus commented 3 years ago

Keeps throwing this error:

Error: child "activity" fails because [child "state" fails because ["state" is not allowed to be empty]]
    at RPCClient._onRpcMessage (C:\git\youtube-music\node_modules\discord-rpc\src\client.js:185:19)
    at IPCTransport.emit (events.js:315:20)
    at C:\git\youtube-music\node_modules\discord-rpc\src\transports\ipc.js:138:18
    at decode (C:\git\youtube-music\node_modules\discord-rpc\src\transports\ipc.js:92:5)
    at Socket.<anonymous> (C:\git\youtube-music\node_modules\discord-rpc\src\transports\ipc.js:120:7)
    at Socket.emit (events.js:315:20)
    at emitReadable_ (_stream_readable.js:555:12)
    at processTicksAndRejections (internal/process/task_queues.js:83:21) {
  code: 4000,
  data: {
    code: 4000,
    message: 'child "activity" fails because [child "state" fails because ["state" is not allowed to be empty]]'
  }
}

(no custom status set on discord, other applications usually work)

Araxeus commented 3 years ago

Can fix the error throwing on start by adding to plugins/discord/back.js

.
.

registerCallback((songInfo) => {
    if(!songInfo.title || !songInfo.artist)
        return
.
.

But discord still doesn't get the rich presence

Checking activity before sending

console.log(activityInfo)
rpc.setActivity(activityInfo);

gives correct metadata, for example

{
  details: 'Honey Bucket',
  state: 'Melvins',
  largeImageKey: 'logo',
  largeImageText: 'Houdini - 1993',
  startTimestamp: 1616773693693,
  endTimestamp: 1616773875693
}

but discord isn't showing anything and I'm not sure how to debug this @semvis123

semvis123 commented 3 years ago

My guess is that the RPC isn't ready/connected when the activity is set, but

rpc.on("ready",()=>{})

should prevent this. So I don't know why this error occurs. It looks like this error only occurs on the first song. Maybe we could retry (with a small delay) after a error occurs, but that doesn't fully solve the problem.

Araxeus commented 3 years ago

Like I said, the error message can be fixed by waiting for the first song to start before setting activity. but even then, discord doesn't show anything (and there is no error thrown) the rpc is ready, the activityInfo is valid.. so idk

To clarify - the discord plugin never worked for me 😋

semvis123 commented 3 years ago

To clarify - the discord plugin never worked for me 😋

Ah okay, what platform are you using, did you install discord using a package manager?

Araxeus commented 3 years ago

Windows 10, Discord installed through discord.com (all other games/applications work)

I think the rpc.login({ clientId }) is rejecting the promise

(even just .catch prints Error) So unless I'm misunderstanding the promise, something is up

semvis123 commented 3 years ago

Ah you are misunderstanding promises, you need to pass a function to catch and then, for ex. .catch(()=>console.log('error')) This will print error if the error occurs, you could also do .catch(console.error) to print the error itself.

But if you do it like this: .catch(console.error('error')) Js will simply execute immediately console.error('error') even if no error is thrown.

Windows 10, Discord installed through discord.com

(all other games/applications work)

Weird, because it works on my Windows machine, have you selected it inside game activities? If so, remove it, because it shouldn't be needed.

Araxeus commented 3 years ago

Thank you for explaining, and sorry for the confusion - both promises are ok But still discord doesn't display anything - haven't selected a custom status / game

27-03-2021 03 07 13