Coder Social home page Coder Social logo

senophyx / discord-rpc Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 7.0 195 KB

An Python wrapper for Discord RPC

Home Page: https://pypi.org/project/discord-rpc

License: MIT License

Python 100.00%
discord discord-rich-presence discord-rpc python rich-presence rpc

discord-rpc's Introduction

Heya Stalker :3

Hey there! I'm Senophyx (Formerly known as LyQuid), a self-taught programmer who has been familiar with the world of programming for more than 3 years, especially Python.

About me:

  • Iā€™m currently working on EterNomm as a founder.

  • Iā€™m currently learning Python, HTML, CSS, Js.

  • First time learning Python August 1, 2021.

  • Ask me about Python.

  • Fun fact I am a Python packages creator, such as Whitehat, Arithmos Cipher.

Connect with me:

TbgVSbycuh Senophyx EterNomm Discord Server Senophyx's Twitter

Discord

Languages:

python javascript html5 css3

Tools:

aws azure firebase gcp heroku linux photoshop

flask pytorch

Stats:

Profile views wakatime

Senophyx's stats

Senophyx's top langs

Senophyx's streak stats

discord-rpc's People

Contributors

allcontributors[bot] avatar dipeshaggarwal avatar k9ur avatar pazkero avatar pukimaa avatar senophyx avatar taifeel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

discord-rpc's Issues

Error when compiled with pyinstaller

image

I'm getting this error when trying to use your package after being compiled into an exe by pyinstaller.

Here is my code

rpc = DiscordRPC.RPC.Set_ID('Example')
button = DiscordRPC.button(button_one_label='Server Invite', button_one_url="https://discord.gg/batch", button_two_label='Website', button_two_url='https://sped.lol')
rpc.set_activity(state='test', details='test', large_image='WORKING_LARGE_IMAGE_KEY', large_text='test', buttons=button, timestamp=rpc.timestamp())
rpc.run()

It works perfectly fine as just a py file but when compiled it breaks

Occasional crash

Copy of #4 since @LyQuid12 won't reopen it.

Sometimes when RPC.set_activity is called, the script crashes with error

    if output['evt'] == "ERROR":
KeyError: 'evt'

Adding debug print for RPC.output, the error is

{'code': 1003, 'message': 'data size does not match what was received'}

Seems to happen regardless of what the activity is set to.

Can't see RPC in discord app

Hey.
I have setup everything, even created the app, but I can't see the status update in discord.
Here is the debug log:

2024-03-28 20:28:43 :: [DEBUG @ presence.py._setup:137] :: Connected to \\?\pipe\discord-ipc-0
2024-03-28 20:28:43 :: [DEBUG @ presence.py._send:164] :: {'v': 1, 'client_id': ''}
2024-03-28 20:28:43 :: [DEBUG @ presence.py._recv:156] :: {'cmd': 'DISPATCH', 'data': {'v': 1, 'config': {'cdn_host': 'cdn.discordapp.com', 'api_endpoint': '//discord.com/api', 'environment': 'production'}, 'user': {'id': '', 'username': '', 'discriminator': '0', 'global_name': '', 'avatar': None, 'avatar_decoration_data': None, 'bot': False, 'flags': 32, 'premium_type': 0}}, 'evt': 'READY', 'nonce': None}
2024-03-28 20:28:43 :: [INFO @ presence.py.handshake:181] :: Connected to account ()
{'cmd': 'SET_ACTIVITY', 'args': {'pid': 19396, 'activity': {'state': 'Test', 'details': 'Test'}}, 'nonce': '221c576b-ba14-4fc9-a5d1-d7381d02e8df'}
2024-03-28 20:28:43 :: [DEBUG @ presence.py._send:164] :: {'cmd': 'SET_ACTIVITY', 'args': {'pid': 19396, 'activity': {'state': 'Test', 'details': 'Test'}}, 'nonce': '221c576b-ba14-4fc9-a5d1-d7381d02e8df'}
2024-03-28 20:28:43 :: [INFO @ presence.py.set_activity:100] :: RPC set

Do you know what might b going wrong?

Add the ability to display the listening status

For some discord applications like spotify and in general media consumption discord has the abilty to display "is listening/watching" with a progress bar and albums/cover art. I can't seem to find a way to recreate this by using this library or the javascript one.

Program hangs sometimes if discord has been in system tray for a long time.

I have been facing this issue intermittently and the only common factor I have managed to find is that it happens when Discord is closed (ie, in the system tray) for a long time.

I managed to isolate the problem to this line https://github.com/Senophyx/Discord-RPC/blob/main/discordrpc/presence.py#L160

enc_header += self.socket.read(header_size)

It seems like when Discord is closed for a long time, the socket enters hibernation and doesn't respond to the request and because of that, the program effectively hangs, waiting for a response.

It can be fixed by opening Discord (from the system tray) but that seems very un-intuitive for end user.

Is there a way to trigger a TimeOut event or something to check if the connection is live?

Occasional crash

Sometimes when RPC.set_activity is called, the script crashes with error

    if output['evt'] == "ERROR":
KeyError: 'evt'

Adding debug print for RPC.output, the error is

{'code': 1003, 'message': 'data size does not match what was received'}

Seems to happen regardless of what the activity is set to.

What is the app_id and how to get it?

https://github.com/LyQuid12/Discord-RPC/blob/main/examples/rpc-with-button.py#L3

What is RPC and how it works?

I have a bot written in python, but I'm not sure how to setup.

The only thing I care about is custom buttons when opening bot's profile on Discord.

Does activity have to be set to gaming?
or other activities also can show the buttons or images?

Is Discord-RPC like a second bot that other bots contact to receive information such as buttons and images?

app_id seems like to mean client_id of a bot.

Sorry, I'm really confused about how it all works.

image

TypeError: DiscordUnix._get_pipe_path() takes 0 positional arguments but 1 was given

  File "project_path/src/__main__.py", line 15, in main
    RPC = discordrpc.RPC.set_id(app_id=CLIENT_ID)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project_path/.venv/lib/python3.11/site-packages/discordrpc/presence.py", line 33, in set_id
    return DiscordUnix(app_id)
           ^^^^^^^^^^^^^^^^^^^
  File "project_path/.venv/lib/python3.11/site-packages/discordrpc/presence.py", line 20, in __init__
    self._connect()
  File "project_path/.venv/lib/python3.11/site-packages/discordrpc/presence.py", line 218, in _connect
    pipe_path = self._get_pipe_path()
                ^^^^^^^^^^^^^^^^^^^^^
TypeError: DiscordUnix._get_pipe_path() takes 0 positional arguments but 1 was given

No such file or directory: '\\\\?\\pipe\\discord-ipc-0'

Full Trace Error:

File "C:\Users\right\AppData\Local\Programs\Python\Python311\Lib\site-packages\discordrpc\presence.py", line 192, in _connect
    self._open = open(path, "w+b")
                 ^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '\\\\?\\pipe\\discord-ipc-0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\right\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Users\right\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "c:\Users\right\Desktop\D\tool.py", line 2185, in rpc
    rpc = discordrpc.RPC.set_id(appID)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\right\AppData\Local\Programs\Python\Python311\Lib\site-packages\discordrpc\presence.py", line 31, in set_id
    return DiscordWindows(app_id)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\right\AppData\Local\Programs\Python\Python311\Lib\site-packages\discordrpc\presence.py", line 20, in __init__
    self._connect()
  File "C:\Users\right\AppData\Local\Programs\Python\Python311\Lib\site-packages\discordrpc\presence.py", line 194, in _connect
    raise Error("Failed to open {!r}: {}".format(path, e))
discordrpc.exceptions.Error: Failed to open '\\\\?\\pipe\\discord-ipc-0': [Errno 2] No such file or directory: '\\\\?\\pipe\\discord-ipc-0'

This just started happening recently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.