discord-rich-presence-plex icon indicating copy to clipboard operation
discord-rich-presence-plex copied to clipboard

Connected to Plex, Not showing in Discord

Open zluckytraveler opened this issue 2 years ago • 46 comments

I have installed plexapi, websocket-client==0.48.0, and and set my configuration in the file properly, it's connected to the server and listening for specific username which it finds, and I have activity status turned on in my profile settings. However nothing is appearing in my profile as a watching/playing status. I'm a bit at a loss and not sure what else to do here.

Output

[05:39:56 PM] [Plex N Chill/06ae7] Logged in as Plex User "Plex.N.Chill"
[05:40:27 PM] [Plex N Chill/06ae7] Connected to Plex Media Server "Plex N Chill"
[05:40:27 PM] [Plex N Chill/06ae7] Listening for PlaySessionStateNotification alerts from user "zak"
[05:51:49 PM] [Plex N Chill/06ae7] <Episode:630835:We-Own-This-City-s01e01>, Session Key: 543, Users: ["Zak"]
[05:51:49 PM] [Plex N Chill/06ae7] Session found
[05:51:49 PM] [Plex N Chill/06ae7] Username "zak" matches "zak", continuing
[05:51:49 PM] [Plex N Chill/06ae7] Opening Discord IPC Pipe
[05:51:49 PM] [Plex N Chill/06ae7] [HANDSHAKE] _UnixSelectorEventLoop.create_unix_connection() got an unexpected keyword argument 'loop'
[05:51:49 PM] [Plex N Chill/06ae7] Closing Discord IPC Pipe
[05:51:49 PM] [Plex N Chill/06ae7] Received Update: {"sessionKey": "541", "clientIdentifier": "396bbacfe499509-com-plexapp-android", "guid": "plex://movie/5d776841961905001eb965e3", "ratingKey": "566460", "url": "", "key": "/library/metadata/566460", "viewOffset": 718323, "playQueueItemID": 156249, "playQueueID": 6550, "state": "playing"}

zluckytraveler avatar Apr 27 '22 01:04 zluckytraveler

I have installed plexapi, websocket-client==0.48.0, and and set my configuration in the file properly, it's connected to the server and listening for specific username which it finds, and I have activity status turned on in my profile settings. However nothing is appearing in my profile as a watching/playing status. I'm a bit at a loss and not sure what else to do here.

Output

[05:39:56 PM] [Plex N Chill/06ae7] Logged in as Plex User "Plex.N.Chill"
[05:40:27 PM] [Plex N Chill/06ae7] Connected to Plex Media Server "Plex N Chill"
[05:40:27 PM] [Plex N Chill/06ae7] Listening for PlaySessionStateNotification alerts from user "zak"
[05:51:49 PM] [Plex N Chill/06ae7] <Episode:630835:We-Own-This-City-s01e01>, Session Key: 543, Users: ["Zak"]
[05:51:49 PM] [Plex N Chill/06ae7] Session found
[05:51:49 PM] [Plex N Chill/06ae7] Username "zak" matches "zak", continuing
[05:51:49 PM] [Plex N Chill/06ae7] Opening Discord IPC Pipe
[05:51:49 PM] [Plex N Chill/06ae7] [HANDSHAKE] _UnixSelectorEventLoop.create_unix_connection() got an unexpected keyword argument 'loop'
[05:51:49 PM] [Plex N Chill/06ae7] Closing Discord IPC Pipe
[05:51:49 PM] [Plex N Chill/06ae7] Received Update: {"sessionKey": "541", "clientIdentifier": "396bbacfe499509-com-plexapp-android", "guid": "plex://movie/5d776841961905001eb965e3", "ratingKey": "566460", "url": "", "key": "/library/metadata/566460", "viewOffset": 718323, "playQueueItemID": 156249, "playQueueID": 6550, "state": "playing"}

you ever figure this out?

dannymichel avatar Apr 27 '22 19:04 dannymichel

I've had this too. Recently installed Windows 11 fresh on a new PC, installed everything right, and got this. Then a week later i try running it again, and it just works. I'm not quite sure what causes this.

jacobmix avatar Apr 27 '22 20:04 jacobmix

I've had this too. Recently installed Windows 11 fresh on a new PC, installed everything right, and got this. Then a week later i try running it again, and it just works. I'm not quite sure what causes this.

I too am having this issue, from what i can tell form google, it seems to be an issue with python 3.10, and having to remove the loop=self.loop) from the arguments, however I haven't been able to find them.

trinity8746 avatar Apr 27 '22 23:04 trinity8746

I got waist-deep in "pyenv" tomfoolery before I decided to just play around with the code myself. Dropped the loop=self.loop from the functions that establish the pipes. Haven't tested much further, but it seems to have corrected whatever issue was introduced with asyncio in Python 3.10. Deprecated functions, and syntax changes I suppose.

Tested on ArchLinux 5.17.5, Python 3.10.4, Discord Stable 126462 (1f5f36e) Don't currently have access to a Windows computer to test. Report back if you have success under Windows.

Before:

    async def handshake(self):
        try:
            if (isLinux):
                self.pipeReader, self.pipeWriter = await asyncio.open_unix_connection(self.IPCPipe, loop=self.loop)
            else:
                self.pipeReader = asyncio.StreamReader(loop=self.loop)
                self.pipeWriter, _ = await self.loop.create_pipe_connection(lambda: asyncio.StreamReaderProtocol(self.pipeReader, loop=self.loop), self.IPCPipe)
            self.write(0, {"v": 1, "client_id": self.clientID})
            await self.read()
            self.running = True
        except Exception as e:
            self.child.log("[HANDSHAKE] " + str(e))

After:

    async def handshake(self):
        try:
            if (isLinux):
                self.pipeReader, self.pipeWriter = await asyncio.open_unix_connection(self.IPCPipe)
            else:
                self.pipeReader = asyncio.StreamReader(loop=self.loop)
                self.pipeWriter, _ = await self.loop.create_pipe_connection(lambda: asyncio.StreamReaderProtocol(self.pipeReader), self.IPCPipe)
            self.write(0, {"v": 1, "client_id": self.clientID})
            await self.read()
            self.running = True
        except Exception as e:
            self.child.log("[HANDSHAKE] " + str(e))

ghost avatar May 02 '22 02:05 ghost

I got waist-deep in "pyenv" tomfoolery before I decided to just play around with the code myself. Dropped the loop=self.loop from the functions that establish the pipes. Haven't tested much further, but it seems to have corrected whatever issue was introduced with asyncio in Python 3.10. Deprecated functions, and syntax changes I suppose.

Tested on ArchLinux 5.17.5, Python 3.10.4, Discord Stable 126462 (1f5f36e) Don't currently have access to a Windows computer to test. Report back if you have success under Windows.

Before:

    async def handshake(self):
        try:
            if (isLinux):
                self.pipeReader, self.pipeWriter = await asyncio.open_unix_connection(self.IPCPipe, loop=self.loop)
            else:
                self.pipeReader = asyncio.StreamReader(loop=self.loop)
                self.pipeWriter, _ = await self.loop.create_pipe_connection(lambda: asyncio.StreamReaderProtocol(self.pipeReader, loop=self.loop), self.IPCPipe)
            self.write(0, {"v": 1, "client_id": self.clientID})
            await self.read()
            self.running = True
        except Exception as e:
            self.child.log("[HANDSHAKE] " + str(e))

After:

    async def handshake(self):
        try:
            if (isLinux):
                self.pipeReader, self.pipeWriter = await asyncio.open_unix_connection(self.IPCPipe)
            else:
                self.pipeReader = asyncio.StreamReader(loop=self.loop)
                self.pipeWriter, _ = await self.loop.create_pipe_connection(lambda: asyncio.StreamReaderProtocol(self.pipeReader), self.IPCPipe)
            self.write(0, {"v": 1, "client_id": self.clientID})
            await self.read()
            self.running = True
        except Exception as e:
            self.child.log("[HANDSHAKE] " + str(e))

So i copied your code over, and got this error:

...\discord-rich-presence-plex-master>py -3 -m discordRichPresencePlex.py
Traceback (most recent call last):
  File "C:\Users\jaive\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Users\jaive\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "C:\C stuff\discord-rich-presence-plex-master\discordRichPresencePlex.py", line 58
    try:
TabError: inconsistent use of tabs and spaces in indentation

Pretty easy fix tho. Just change the all the indent spaces to "tab spaces" If you got NotePad++ just go to Edit (Top left next to "File") -> Blank Operations -> Space to Tab (All) Seems to be working. I'll link to this from my old installation guide since this fix would probably help many. Thanks for the great fix.

jacobmix avatar May 02 '22 10:05 jacobmix

@772399286 Exactly what file and line is it that you had to edit and remove the loop=self.loop from? I'm using Mac as well, if thats of any help.

zluckytraveler avatar May 08 '22 21:05 zluckytraveler

Line 63 requires the change for MacOS and Windows. 60 would be for Linux-based operating systems.

self.pipeWriter, _ = await self.loop.create_pipe_connection(lambda: asyncio.StreamReaderProtocol(self.pipeReader, loop = self.loop), self.IPCPipe)

should become:

self.pipeWriter, _ = await self.loop.create_pipe_connection(lambda: asyncio.StreamReaderProtocol(self.pipeReader), self.IPCPipe)

Confirm if that change works for you. Would help anybody else that is trying to use this script on MacOS.

ghost avatar May 08 '22 22:05 ghost

@772399286 What exactly is the name of the file that needs to be edited and where can I locate it?

zluckytraveler avatar May 09 '22 18:05 zluckytraveler

@772399286 What exactly is the name of the file that needs to be edited and where can I locate it?

This project revolves around a single python file. The only file. -- discordRichPresencePlex.py

ghost avatar May 09 '22 18:05 ghost

@772399286 What exactly is the name of the file that needs to be edited and where can I locate it?

This project revolves around a single python file. The only file. -- discordRichPresencePlex.py

Thanks I found it, I wasn't sure if it was something do within python 3.10 file or not.

I've applied the changes you suggested for line 63, and I am still receiving an error.

[12:11:08 PM] [Plex N Chill/4becc] Session found
[12:11:08 PM] [Plex N Chill/4becc] Username "zak" matches "zak", continuing
[12:11:08 PM] [Plex N Chill/4becc] Opening Discord IPC Pipe
[12:11:08 PM] [Plex N Chill/4becc] [HANDSHAKE] _UnixSelectorEventLoop.create_unix_connection() got an unexpected keyword argument 'loop'
[12:11:08 PM] [Plex N Chill/4becc] Closing Discord IPC Pipe
[12:11:09 PM] [Plex N Chill/4becc] Received Update: {"sessionKey": "441", "clientIdentifier": "8u2jnsm6xyrldlbbzcvldqni", "guid": "", "ratingKey": "589650", "url": "", "key": "/library/metadata/589650", "viewOffset": 290000, "playQueueItemID": 244766, "playQueueID": 10562, "state": "playing", "transcodeSession": "kj9w9fzq5c1eux0h8n3vrd4w"}```

zluckytraveler avatar May 09 '22 19:05 zluckytraveler

@772399286 What exactly is the name of the file that needs to be edited and where can I locate it?

This project revolves around a single python file. The only file. -- discordRichPresencePlex.py

Thanks I found it, I wasn't sure if it was something do within python 3.10 file or not.

I've applied the changes you suggested for line 63, and I am still receiving an error.

[12:11:08 PM] [Plex N Chill/4becc] Session found
[12:11:08 PM] [Plex N Chill/4becc] Username "zak" matches "zak", continuing
[12:11:08 PM] [Plex N Chill/4becc] Opening Discord IPC Pipe
[12:11:08 PM] [Plex N Chill/4becc] [HANDSHAKE] _UnixSelectorEventLoop.create_unix_connection() got an unexpected keyword argument 'loop'
[12:11:08 PM] [Plex N Chill/4becc] Closing Discord IPC Pipe
[12:11:09 PM] [Plex N Chill/4becc] Received Update: {"sessionKey": "441", "clientIdentifier": "8u2jnsm6xyrldlbbzcvldqni", "guid": "", "ratingKey": "589650", "url": "", "key": "/library/metadata/589650", "viewOffset": 290000, "playQueueItemID": 244766, "playQueueID": 10562, "state": "playing", "transcodeSession": "kj9w9fzq5c1eux0h8n3vrd4w"}```

Ah, interesting. Guess you'll need to change line 60 as well. Guess it makes sense that MacOS would fall into the Linux/UNIX category. Replace line 60 with:

self.pipeReader, self.pipeWriter = await asyncio.open_unix_connection(self.IPCPipe)

Let me know if that helps.

ghost avatar May 09 '22 19:05 ghost

@772399286 That did not seem to work either, I tried removing loop=self.loop) from line 62 as well, and on both occasions it returned with the same output.

[12:32:17 PM] [Plex N Chill/75af0] Session found
[12:32:17 PM] [Plex N Chill/75af0] Username "zak" matches "zak", continuing
[12:32:17 PM] [Plex N Chill/75af0] Opening Discord IPC Pipe
[12:32:52 PM] [Plex N Chill/75af0] No updates from session key 444, stopping
[12:32:52 PM] [Plex N Chill/75af0] Closing Discord IPC Pipe
/Applications/Apps/Programs/Plex-Discord-Rich-Presence/discordRichPresencePlex.py:100: RuntimeWarning: coroutine 'StreamReader.read' was never awaited
  pass
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[12:32:57 PM] [Plex N Chill/75af0] Request for clients list to check connection: []
[12:33:57 PM] [Plex N Chill/75af0] Request for clients list to check connection: []```

zluckytraveler avatar May 09 '22 19:05 zluckytraveler

@772399286 I ended up giving it another shot, and just started from scratch setting up the file new, and removed line 63 & 60, it seems to be connected and finally running properly now!

Output:

[01:02:27 PM] [Plex N Chill/28d34] <Episode:668565:Wicked-Tuna-s11e11>, Session Key: 444, Users: ["Zak"]
[01:02:27 PM] [Plex N Chill/28d34] Session found
[01:02:27 PM] [Plex N Chill/28d34] Username "zak" matches "zak", continuing
[01:02:27 PM] [Plex N Chill/28d34] [WRITE] {"cmd": "SET_ACTIVITY", "args": {"activity": {"details": "Wicked Tuna", "state": "08:54/44:27 \u00b7 S11 \u00b7 E11 - Episode 11", "assets": {"large_text": "Watching a TV Show", "large_image": "logo", "small_text": "Paused", "small_image": "paused"}}, "pid": 92599}, "nonce": "1652126547.76294922828674316406"}
[01:02:27 PM] [Plex N Chill/28d34] [READ] {'cmd': 'SET_ACTIVITY', 'data': {'details': 'Wicked Tuna', 'state': '08:54/44:27 · S11 · E11 - Episode 11', 'assets': {'large_text': 'Watching a TV Show', 'large_image': '413413572194992129', 'small_text': 'Paused', 'small_image': '413414293112094730'}, 'name': 'Plex', 'application_id': '413407336082833418', 'type': 0}, 'evt': None, 'nonce': '1652126547.76294922828674316406'}

The only issue now, is that there is nothing being showed under my profile as being played... Is there something else besides just running this application I need to enable or do?

I've included a screenshot of my Discord profile and my Activity Status setting. I am using Discord Dektop App on the same machine that the program is running on via terminal if that helps provide any context as well

Profile Activity Status

zluckytraveler avatar May 09 '22 20:05 zluckytraveler

@772399286 I ended up giving it another shot, and just started from scratch setting up the file new, and removed line 63 & 60, it seems to be connected and finally running properly now!

Output:

[01:02:27 PM] [Plex N Chill/28d34] <Episode:668565:Wicked-Tuna-s11e11>, Session Key: 444, Users: ["Zak"]
[01:02:27 PM] [Plex N Chill/28d34] Session found
[01:02:27 PM] [Plex N Chill/28d34] Username "zak" matches "zak", continuing
[01:02:27 PM] [Plex N Chill/28d34] [WRITE] {"cmd": "SET_ACTIVITY", "args": {"activity": {"details": "Wicked Tuna", "state": "08:54/44:27 \u00b7 S11 \u00b7 E11 - Episode 11", "assets": {"large_text": "Watching a TV Show", "large_image": "logo", "small_text": "Paused", "small_image": "paused"}}, "pid": 92599}, "nonce": "1652126547.76294922828674316406"}
[01:02:27 PM] [Plex N Chill/28d34] [READ] {'cmd': 'SET_ACTIVITY', 'data': {'details': 'Wicked Tuna', 'state': '08:54/44:27 · S11 · E11 - Episode 11', 'assets': {'large_text': 'Watching a TV Show', 'large_image': '413413572194992129', 'small_text': 'Paused', 'small_image': '413414293112094730'}, 'name': 'Plex', 'application_id': '413407336082833418', 'type': 0}, 'evt': None, 'nonce': '1652126547.76294922828674316406'}

The only issue now, is that there is nothing being showed under my profile as being played... Is there something else besides just running this application I need to enable or do?

I've included a screenshot of my Discord profile and my Activity Status setting. I am using Discord Dektop App on the same machine that the program is running on via terminal if that helps provide any context as well

Profile Activity Status

Fantastic! Looks like everything is talking nicely on the Plex side of things. Make sure to enable Activity Status in the Discord settings. I believe that is the only setting in Discord you have to allow for the rich presence / status updates.

ghost avatar May 09 '22 20:05 ghost

@772399286 I ended up giving it another shot, and just started from scratch setting up the file new, and removed line 63 & 60, it seems to be connected and finally running properly now! Output:

[01:02:27 PM] [Plex N Chill/28d34] <Episode:668565:Wicked-Tuna-s11e11>, Session Key: 444, Users: ["Zak"]
[01:02:27 PM] [Plex N Chill/28d34] Session found
[01:02:27 PM] [Plex N Chill/28d34] Username "zak" matches "zak", continuing
[01:02:27 PM] [Plex N Chill/28d34] [WRITE] {"cmd": "SET_ACTIVITY", "args": {"activity": {"details": "Wicked Tuna", "state": "08:54/44:27 \u00b7 S11 \u00b7 E11 - Episode 11", "assets": {"large_text": "Watching a TV Show", "large_image": "logo", "small_text": "Paused", "small_image": "paused"}}, "pid": 92599}, "nonce": "1652126547.76294922828674316406"}
[01:02:27 PM] [Plex N Chill/28d34] [READ] {'cmd': 'SET_ACTIVITY', 'data': {'details': 'Wicked Tuna', 'state': '08:54/44:27 · S11 · E11 - Episode 11', 'assets': {'large_text': 'Watching a TV Show', 'large_image': '413413572194992129', 'small_text': 'Paused', 'small_image': '413414293112094730'}, 'name': 'Plex', 'application_id': '413407336082833418', 'type': 0}, 'evt': None, 'nonce': '1652126547.76294922828674316406'}

The only issue now, is that there is nothing being showed under my profile as being played... Is there something else besides just running this application I need to enable or do? I've included a screenshot of my Discord profile and my Activity Status setting. I am using Discord Dektop App on the same machine that the program is running on via terminal if that helps provide any context as well Profile Activity Status

Fantastic! Looks like everything is talking nicely on the Plex side of things. Make sure to enable Activity Status in the Discord settings. I believe that is the only setting in Discord you have to allow for the rich presence / status updates.

My eyes glossed over your images you posted. It appears you already have the activity status enabled. Can you confirm which Mac you have? Might be a compatibility issue with those newer M1 chips

ghost avatar May 09 '22 20:05 ghost

@772399286 I have a 2014 MacBook Pro Retina running on macOS Big Sur Version 11.6.5

What could be wrong or am I missing here?

zluckytraveler avatar May 09 '22 20:05 zluckytraveler

@772399286 I have a 2014 MacBook Pro Retina running on macOS Big Sur Version 11.6.5

Hmmm. I unfortunately do not have access to MacOS to test this. The fact that you are getting those READ/WRITE lines in your log means it at least sees Discord is open and available.

Keep an eye out for these lines specifically in the log as a great indication that Discord is seen by the python script:

[00:00:00 AM] [Server/c0000] Opening Discord IPC Pipe
[00:00:00 AM] [Server/c0000] [WRITE] {"v": 1, "client_id": "000000000000000000"}
[00:00:00 AM] [Server/c0000] [READ] {'cmd': 'DISPATCH', 'data': {'v': 1, 'config': {'cdn_host': 'cdn.discordapp.com', 'api_endpoint': '//discord.com/api', 'environment': 'production'}, 'user': {'id': '000000000000000000', 'username': 'iamadiscorduser', 'discriminator': '0000', 'avatar': '00000000000000000000000000000000', 'avatar_decoration': None, 'bot': False, 'flags': 0, 'premium_type': 0}}, 'evt': 'READY', 'nonce': None}

I am unfortunately unequipped to troubleshoot this issue any further both on the operating system side of things as well as python knowledge/experience. Hopefully somebody is able to step in and shed more light on this issue and perform additional testing. We could also be hitting MacOS app permissions which is a whole can of worms... (make sure you are running the script as the same user Discord is running as. Never run this script as an elevated user / root).

It could also be beneficial to test an alternate rich presence app, such as this one: https://github.com/ThatOneCalculator/DiscordRPCMaker At least just to verify it isn't just a rich presence bug in the latest version of MacOS Discord or something.

Also to those reading that are extending the life of this script, I have tested this script with the latest PlexAPI and websocket-client libraries with success. As of May 9th, 2022, this script seems to work with Python 3.10.4, PlexAPI 4.10.1, and websocket-client 1.3.2. Tested from ArchLinux 5.17.5. Not sure there is a need to hold websocket-client back on 0.48.0 anymore.

If phineas05 doesn't have plans to maintain this script anymore, it might be time for somebody to step forward and fork this (preferably somebody with adequate Python knowledge). Jacobmix has done a fantastic job of consolidating several fixes into a single thread, but maybe it's time to consolidate them into a dedicated fork we can all point to. Just some food for thought.

Happy troubleshooting.

ghost avatar May 09 '22 21:05 ghost

@772399286 I went ahead and checked to make sure permissions were ok, as you can see read, write, and execute are all allowed. I even went as far as to check within the disk permissions in the Privacy settings, and made sure incoming/outgoing connections are not being blocked by any firewall for any kind of reason, so I think that side of it is handled.

Lucky@Luckys-Mac Plex-Discord-Rich-Presence % ls -l
total 48
-rw-r--r--  1 Lucky  staff   1066 Apr 26 17:34 LICENSE
-rw-r--r--  1 Lucky  staff   2556 Apr 26 17:34 README.md
-rwxr-xr-x@ 1 Lucky  staff  14206 May  9 12:54 discordRichPresencePlex.py

I am only using this computer as a single user, never had to or wanted to use it as an alternative, nor am I running in root or via sudo or anything like that, I've only used this computer as Lucky

I did try to use the DiscordRPCMakerapplication like you had suggested, and I am receiving the exact same problem, with nothing being shown for user activity.

Discord Desktop Client Version: 0.0.266

@jacobmix Could you possibly help me out, I'm really struggling to find the problem and how to fix it, any help would be highly appreciated.

zluckytraveler avatar May 09 '22 22:05 zluckytraveler

@772399286 So I ended up asking opening a support ticket in the DiscordRPCMake Support Server, and immediately they knew what the issue was. I'm surprised no one caught it here in the profile image either though.

After all this the reason it's not working is because my profile status is set to invisible. I had no clue that would stop the activity status from working, I feel real stupid now. Sorry for all the confusion.

With this said and now finally working, I am wondering is there a specific line of code in the file which could be changed in order for the Plex Logo to be changed to a custom photo for the activity status?

zluckytraveler avatar May 09 '22 23:05 zluckytraveler

@772399286 So I ended up asking opening a support ticket in the DiscordRPCMake Support Server, and immediately they knew what the issue was. I'm surprised no one caught it here in the profile image either though.

After all this the reason it's not working is because my profile status is set to invisible. I had no clue that would stop the activity status from working, I feel real stupid now. Sorry for all the confusion.

With this said and now finally working, I am wondering is there a specific line of code in the file which could be changed in order for the Plex Logo to be changed to a custom photo for the activity status?

LMAO. Of course! Glad it ended up being something simple.

The picture seems to get set on line 322. You might be able to manually specify a direct http link, but if I'm being honest I'm not entirely sure where the Plex logo even comes from. Directly from the Plex Media Server? Or maybe stored in a Discord application (activity asset images, for example) that phineas05 likely created. The latter is likely the case as there is a unique Discord ID stored in the project on line 19 [413407336082833418], which is likely his unique Discord application id.

ghost avatar May 09 '22 23:05 ghost

@772399286 Wow it was actually way easier than I thought it would be. Just had to make an application on Discord Developer add the client id to line 19, and upload the image I wanted to art assets,, and name it "logo", that's it!

Well next is containerizing the application in docker...hopefully that won't be too hard though. BTW.. do you know how to change the wording from PLAYING A GAME to something more customizable like STREAMING or CURRENTLY WATCHING?

Thanks for the help!

zluckytraveler avatar May 10 '22 03:05 zluckytraveler

@772399286 Wow it was actually way easier than I thought it would be. Just had to make an application on Discord Developer add the client id to line 19, and upload the image I wanted to art assets,, and name it "logo", that's it!

Well next is containerizing the application in docker...hopefully that won't be too hard though. BTW.. do you know how to change the wording from PLAYING A GAME to something more customizable like STREAMING or CURRENTLY WATCHING?

Thanks for the help!

Happy to help where I can! You might be able to pass a "type" variable through containing the integer that indicates if it's a game, music, stream, etc. Check out this documentation: https://discord.com/developers/docs/topics/gateway#activity-object-activity-types

In discord-rich-presence-plex's case, you'd maybe want to add something like this (around line 317):

activity = {
    "details": title,
    "state": extra,
    "type": 0,
    "assets": {
        "large_text": largeText,
        "large_image": "logo",
        "small_text": state.capitalize(),
        "small_image": state
    },
}

Note the additional "type" parameter that is getting passed through. The integer should match what is documented in that discord developer/api link above.

Would need to be tested. Not sure if this works.

ghost avatar May 10 '22 15:05 ghost

You might be able to pass a "type" variable through containing the integer that indicates if it's a game, music, stream, etc. Check out this documentation: https://discord.com/developers/docs/topics/gateway#activity-object-activity-types

Note the additional "type" parameter that is getting passed through. The integer should match what is documented in that discord developer/api link above.

Would need to be tested. Not sure if this works.

I'm in the process of refactoring the project. I tried this a while back and it doesn't seem to work.

Refer to this page where it says the following:

ActivityType is strictly for the purpose of handling events that you receive from Discord; though the SDK/our API will not reject a payload with an ActivityType sent, it will be discarded and will not change anything in the client.

phin05 avatar May 10 '22 15:05 phin05

You might be able to pass a "type" variable through containing the integer that indicates if it's a game, music, stream, etc. Check out this documentation: https://discord.com/developers/docs/topics/gateway#activity-object-activity-types Note the additional "type" parameter that is getting passed through. The integer should match what is documented in that discord developer/api link above. Would need to be tested. Not sure if this works.

I'm in the process of refactoring the project. I tried this a while back and it doesn't seem to work.

Refer to this page where it says the following:

ActivityType is strictly for the purpose of handling events that you receive from Discord; though the SDK/our API will not reject a payload with an ActivityType sent, it will be discarded and will not change anything in the client.

That's quite a shame and unfortunate, hopefully soon though!

One thing that I've noticed is this requires it to be running on the same machine as Discord Desktop Client which is not ideal having to keep a machine on 24/7 for it to work all the time. Would be nice if we were able to host it online, and just have to add a discord user id or something similar, or even specifically for adding it to anyone within a guild that'd automatically pick up their user id based on the guild id, so it can easily be shared for everyone.

I tried to make a dockerfile for this as well, and couldn't get it to successfully run with docker. Does anyone how the dockerfile should be set up?

zluckytraveler avatar May 10 '22 22:05 zluckytraveler

One thing that I've noticed is this requires it to be running on the same machine as Discord Desktop Client which is not ideal having to keep a machine on 24/7 for it to work all the time. Would be nice if we were able to host it online, and just have to add a discord user id or something similar, or even specifically for adding it to anyone within a guild that'd automatically pick up their user id based on the guild id, so it can easily be shared for everyone.

As far as I can tell, it's not possible to make this work without having to connect to a local Discord client.

The program works by directly communicating with the Discord client process using inter-process communication and makes remote procedure calls to set the rich presence. Connecting to the Discord client's local RPC WebSocket server is another option but even that method requires the client to be running.

Relevant documentation for this on the Discord Developer Portal: https://discord.com/developers/docs/topics/rpc https://discord.com/developers/docs/game-sdk/sdk-starter-guide

It might be possible to connect to the Discord WebSocket Gateway to set the rich presence without using IPC/RPC but I believe that would fall under self-botting which is forbidden by Discord.

phin05 avatar May 10 '22 23:05 phin05

@phineas05 Thanks for the reply this makes more sense now. Does make me wonder how other applications are able to run separate like Spotify or youtube as an example, just something I think about.

I was able to create the dockerfile just now which the container is running successfully (This is all local on the same machine as Discord). However it looks like I am receiving an error which I'm not sure how to fix. any suggestion?

Dockerfile:

FROM python:3
WORKDIR /src
RUN pip3 install plexapi
RUN pip3 install websocket-client==0.48.0
COPY . .
CMD [ "python3", "/src/bot.py" ]

Output Error:

[11:11:21 PM] [Plex N Chill/9321f] Opening Discord IPC Pipe
[11:11:21 PM] [Plex N Chill/9321f] [HANDSHAKE] [Errno 2] No such file or directory
[11:11:21 PM] [Plex N Chill/9321f] Closing Discord IPC Pipe

zluckytraveler avatar May 10 '22 23:05 zluckytraveler

Does make me wonder how other applications are able to run separate like Spotify or youtube as an example, just something I think about.

Spotify rich presence works differently because it's officially integrated into the application by Discord. https://support.discord.com/hc/en-us/articles/360000167212-Discord-Spotify-Connection

I'm not aware of any official YouTube rich presence integrations.

I was able to create the dockerfile just now which the container is running successfully (This is all local on the same machine as Discord). However it looks like I am receiving an error which I'm not sure how to fix. any suggestion?

Not sure if there's a fix for that. It's because running the script in Docker would isolate it from your Discord client and hence it wouldn't be able to access the Discord client's named IPC pipe.

phin05 avatar May 10 '22 23:05 phin05

I have refactored and cleaned up the project. Refer to the README for the updated basic installation instructions/requirements.

@772399286 @zluckytraveler Whenever possible, could you two confirm that the new code still works fine on your computers / operating systems? I've tested it on Windows 10 and everything appears to be working as intended.

phin05 avatar May 11 '22 01:05 phin05

@phineas05 It no longer works for me. Program will run without showing any errors, but the RPC wont display to discord anymore.

With your new set up, I am receiving an error as well, which repeats over and over.

[10-05-2022 06:11:26 PM] [INFO] Discord Rich Presence for Plex - v2.0.2
[10-05-2022 06:11:27 PM] [INFO] [Plex N Chill/8C85D] Signed in as Plex User "Plex.N.Chill"
[10-05-2022 06:11:27 PM] [INFO] [Plex N Chill/8C85D] Connecting to Plex Media Server "Plex N Chill"
[10-05-2022 06:11:57 PM] [INFO] [Plex N Chill/8C85D] Connected to Plex Media Server "Plex N Chill"
[10-05-2022 06:11:57 PM] [ERROR] [Plex N Chill/8C85D] Failed to connect to Plex Media Server "Plex N Chill": AlertListener.__init__() takes from 2 to 3 positional arguments but 4 were given
[10-05-2022 06:11:57 PM] [ERROR] [Plex N Chill/8C85D] Reconnecting in 10 seconds
[10-05-2022 06:12:08 PM] [INFO] [Plex N Chill/8C85D] Signed in as Plex User "Plex.N.Chill"
[10-05-2022 06:12:08 PM] [INFO] [Plex N Chill/8C85D] Connecting to Plex Media Server "Plex N Chill"
[10-05-2022 06:12:38 PM] [INFO] [Plex N Chill/8C85D] Connected to Plex Media Server "Plex N Chill"
[10-05-2022 06:12:38 PM] [ERROR] [Plex N Chill/8C85D] Failed to connect to Plex Media Server "Plex N Chill": AlertListener.__init__() takes from 2 to 3 positional arguments but 4 were given

zluckytraveler avatar May 11 '22 01:05 zluckytraveler

@phineas05 It no longer works for me. Program will run without showing any errors, but the RPC wont display to discord anymore.

With your new set up, I am receiving an error as well. Failed to connect to Plex Media Server "Plex N Chill": AlertListener.__init__() takes from 2 to 3 positional arguments but 4 were given

Your version of PlexAPI might be outdated. Could you try running python -m pip install PlexAPI -U to update to the latest version?

phin05 avatar May 11 '22 01:05 phin05