Giter Site home page Giter Site logo

discord-rpc's Introduction

Discord RPC

"Discord RPC is a library for interfacing your game with a locally running Discord desktop client"

Status:

Stars Badge Stars Badge Forks Badge Issues Badge

Requirements:

Python
3.0 and above

Setup:

clone this to your local device

git clone https://github.com/niveshbirangal/discord-rpc.git

Go to the developer portal and create an application

https://discord.com/developers/applications



Add assets(image) to your application



Select images and clear all fields except PARTY ID and JOIN SECRET



Now go to example.py, put your client id, and change the activity code according to your best fit
 activity = {
            "state": "Adobe",  # anything you like
            "details": "Editing",  # anything you like
            "timestamps": {
                "start": start_time
            },
            "assets": {
                "small_text": "Adobe",  # anything you like
                "small_image": "adobe",  # must match the image key
                "large_text": "Illustrator",  # anything you like
                "large_image": "illustrator"  # must match the image key
            }
        }

Make sure your desktop app is running and then run the example.py

python3 example.py

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Connect with me:

niveshb.com niveshbirangal | LinkedIn niveshbirangal | Instagram niveshbirangal | YouTube

discord-rpc's People

Contributors

niveshbirangal avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

discord-rpc's Issues

Transport Endpoint is Not Connected

Traceback (most recent call last):
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/threads/discord_rpc_thread.py", line 15, in run
rpc_obj = rpc.DiscordIpcClient.for_platform(client_id)
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/rpc.py", line 44, in for_platform
return UnixDiscordIpcClient(client_id)
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/rpc.py", line 36, in init
self._do_handshake()
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/rpc.py", line 51, in _do_handshake
ret_op, ret_data = self.send_recv({'v': 1, 'client_id': self.client_id}, op=OP_HANDSHAKE)
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/rpc.py", line 99, in send_recv
self.send(data, op)
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/rpc.py", line 107, in send
self._write(header)
File "/home/thekralgame/PycharmProjects/TheModpackDatabase/rpc.py", line 191, in _write
self._sock.sendall(data)
OSError: [Errno 107] Transport endpoint is not connected

i get this error with example.py.
Discord Client is open.
I write application id in general information to client_id

Discord RPC Buttons

discord now allows you to add a maximum of 2 buttons with links for you rich presence, this rpc doesnt seem to be able to do that currently and i found one example but i cannot get it to work button1 = tk.Button (text = "Enable", font = ("", 30), width = 15, height = 5, command = callback)

Image not working?

For some reason when i add my own client id it doesn't work?

it only worked on 1 device which is my friend's phone for some reason

Rpc connect issue

Hi i followed the readme.md and on running a (modified version) of example.py

`import rpc
import time
from time import mktime

client_id = '' # Your application's client ID as a string. # I didn't include my client id in the issue
rpc_obj = rpc.DiscordIpcClient.for_platform(client_id) # Send the client ID to the rpc module
print("RPC connection successful.")

def rpc_connect():

time.sleep(5)
start_time = mktime(time.localtime())
while True:
    activity = {
            "state": "Minecraft",  # anything you like
            "details": "Playing",  # anything you like
            "timestamps": {
                "start": start_time
            },
            "assets": {
                #"small_text": "",  # anything you like
                #"small_image": "",  # must match the image key
                "large_text": "Pycraft Launcher",  # anything you like
                "large_image": "minecraft"  # must match the image key
            }
        }
    rpc_obj.set_activity(activity)

rpc_connect()`

I get this error:

RPC connection successful.
Traceback (most recent call last):
File "rpc_connect.py", line 30, in
rpc_connect()
File "rpc_connect.py", line 28, in rpc_connect
rpc_obj.set_activity(activity)
File "/home/anonymous/Desktop/python_programs/python_minecraft/pycraft/rpc.py", line 137, in set_activity
self.send(data)
File "/home/anonymous/Desktop/python_programs/python_minecraft/pycraft/rpc.py", line 116, in send
self._write(data_bytes)
File "/home/anonymous/Desktop/python_programs/python_minecraft/pycraft/rpc.py", line 200, in _write
self._sock.sendall(data)
ConnectionResetError: [Errno 104] Connection reset by peer

However i can still my program in the status.

image

What is happening here exactly?

(sorry for poor editing of comment ๐Ÿ˜… )

discordrpc.exceptions.Error: Failed to open '\\\\?\\pipe\\discord-ipc-0': [Errno 2] No such file or directory: '\\\\?\\pipe\\discord-ipc-0'

Traceback (most recent call last):
File "D:\git\ply_alib\data\libraries\Inters.py", line 54, in
rpc_connect()
File "D:\git\ply_alib\data\libraries\Inters.py", line 39, in rpc_connect
rpc = discordrpc.RPC(app_id=herewasmyapp_id, output=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SystemX\AppData\Local\Programs\Python\Python312\Lib\site-packages\discordrpc\presence.py", line 41, in init
self.ipc = WindowsPipe(app_id)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\SystemX\AppData\Local\Programs\Python\Python312\Lib\site-packages\discordrpc\presence.py", line 137, in init
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'

Playing/watching/streaming

Well, in the discord-rich presence it usually says: Playing/watching or Streaming. Those are the default ones. How can I change the playing for the watching or streaming?. It is possible to change the playing for another word you want?

Socket is not connected

Hi I tried your tutorial, but i got this error in the console after "python3 example.py"

Demo for python-discord-rpc
failed to open '/var/folders/_6/gbxvg51d3wg13b34lkc7cqwr0000gn/T/discord-ipc-0': [Errno 61] Connection refused
Traceback (most recent call last):
File "example.py", line 6, in
rpc_obj = rpc.DiscordIpcClient.for_platform(client_id)
File "/Users/robertzubrycki/Work/learning/discord-rpc/rpc.py", line 53, in for_platform
return UnixDiscordIpcClient(client_id)
File "/Users/robertzubrycki/Work/learning/discord-rpc/rpc.py", line 45, in init
self._do_handshake()
File "/Users/robertzubrycki/Work/learning/discord-rpc/rpc.py", line 60, in _do_handshake
ret_op, ret_data = self.send_recv({'v': 1, 'client_id': self.client_id}, op=OP_HANDSHAKE)
File "/Users/robertzubrycki/Work/learning/discord-rpc/rpc.py", line 108, in send_recv
self.send(data, op)
File "/Users/robertzubrycki/Work/learning/discord-rpc/rpc.py", line 116, in send
self._write(header)
File "/Users/robertzubrycki/Work/learning/discord-rpc/rpc.py", line 201, in _write
self._sock.sendall(data)
OSError: [Errno 57] Socket is not connected

not running due to syntax error

I ran it and i get this error:

  File "example.py", line 1, in <module>
    import rpc
  File "/Users/pythonpresence/Desktop/discord_rich_presence/discord-rpc/rpc.py", line 30
    class DiscordIpcClient(metaclass=ABCMeta):
                                    ^

discord is open and I followed all the steps.

This is what happens when i run python3 example.py

โ”Œโ”€[deadshot@parrot]โ”€[~/Desktop/discord-rpc]
โ””โ”€โ”€โ•ผ $python3 example.py
Demo for python-discord-rpc Adobe illustrator
Traceback (most recent call last):
File "example.py", line 7, in
rpc_obj = rpc.DiscordIpcClient.for_platform(client_id) # Send the client ID to the rpc module
File "/home/deadshot/Desktop/discord-rpc/rpc.py", line 52, in for_platform
return UnixDiscordIpcClient(client_id)
File "/home/deadshot/Desktop/discord-rpc/rpc.py", line 44, in init
self._do_handshake()
File "/home/deadshot/Desktop/discord-rpc/rpc.py", line 59, in _do_handshake
ret_op, ret_data = self.send_recv({'v': 1, 'client_id': self.client_id}, op=OP_HANDSHAKE)
File "/home/deadshot/Desktop/discord-rpc/rpc.py", line 107, in send_recv
self.send(data, op)
File "/home/deadshot/Desktop/discord-rpc/rpc.py", line 115, in send
self._write(header)
File "/home/deadshot/Desktop/discord-rpc/rpc.py", line 200, in _write
self._sock.sendall(data)
OSError: [Errno 107] Transport endpoint is not connected

OSError

Hello, I'm on a Linux Mint computer, and after all the steps indicated, I have this error that appears:
image
Please, can you help me ?

Automatically run the 'game'

Is there a way to have the status automatically run or run when I have a certain app open so I don't need to keep PyCharm open?

OSError: [Errno 107] Transport endpoint is not connected.

After run this:
marvellous@Marvellous-ROG:~/Documents/discord-rpc-master$ python3 example.py

Demo for python-discord-rpc
Traceback (most recent call last):
  File "example.py", line 6, in <module>
    rpc_obj = rpc.DiscordIpcClient.for_platform(client_id) #Send the client ID to the rpc module
  File "/home/marvellous/Documents/discord-rpc-master/rpc.py", line 53, in for_platform
    return UnixDiscordIpcClient(client_id)
  File "/home/marvellous/Documents/discord-rpc-master/rpc.py", line 45, in __init__
    self._do_handshake()
  File "/home/marvellous/Documents/discord-rpc-master/rpc.py", line 60, in _do_handshake
    ret_op, ret_data = self.send_recv({'v': 1, 'client_id': self.client_id}, op=OP_HANDSHAKE)
  File "/home/marvellous/Documents/discord-rpc-master/rpc.py", line 108, in send_recv
    self.send(data, op)
  File "/home/marvellous/Documents/discord-rpc-master/rpc.py", line 116, in send
    self._write(header)
  File "/home/marvellous/Documents/discord-rpc-master/rpc.py", line 201, in _write
    self._sock.sendall(data)
OSError: [Errno 107] Transport endpoint is not connected

Error

While I was using this I got these errors:

Demo for python-discord-rpc Adobe illustrator
Traceback (most recent call last):
File "example.py", line 7, in
rpc_obj = rpc.DiscordIpcClient.for_platform(client_id) # Send the client ID to the rpc module
File "/home/runner/discord-rpc/rpc.py", line 52, in for_platform
return UnixDiscordIpcClient(client_id)
File "/home/runner/discord-rpc/rpc.py", line 44, in init
self._do_handshake()
File "/home/runner/discord-rpc/rpc.py", line 59, in _do_handshake
ret_op, ret_data = self.send_recv({'v': 1, 'client_id': self.client_id}, op=OP_HANDSHAKE)
File "/home/runner/discord-rpc/rpc.py", line 107, in send_recv
self.send(data, op)
File "/home/runner/discord-rpc/rpc.py", line 115, in send
self._write(header)
File "/home/runner/discord-rpc/rpc.py", line 200, in _write
self._sock.sendall(data)
OSError: [Errno 107] Transport endpoint is not connected

I feel like I made a stupid mistake while reading it I'll try to fix it.

Error when trying to edit activity

I can edit the actual activity easily, but my script seems to create problems, I got this error

Traceback (most recent call last):
  File "C:\Users\imprv\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\imprv\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\imprv\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "C:\Users\imprv\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\imprv\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "g:\Projets\Chocolate\app.py", line 1216, in sendDiscordPresence
    rpc_obj.set_activity(activity)
  File "g:\Projets\Chocolate\rpc.py", line 137, in set_activity
    self.send(data)
  File "g:\Projets\Chocolate\rpc.py", line 115, in send
    self._write(header)
  File "g:\Projets\Chocolate\rpc.py", line 160, in _write
    self._f.flush()
OSError: [Errno 22] Invalid argument

here's the script

@app.route("/sendDiscordPresence/<name>/<actualDuration>/<totalDuration>")
def sendDiscordPresence(name, actualDuration, totalDuration):
    actualDuration = actualDuration
    totalDuration = totalDuration
    rpc_obj = rpc.DiscordIpcClient.for_platform(client_id)
    activity = {
        "state": "Chocolate",  # anything you like
        "details": f"Watching {name} | {actualDuration}/{totalDuration}",  # anything you like
        "assets": {
            "small_text": "Chocolate",  # anything you like
            "small_image": "None",  # must match the image key
            "large_text": "Chocolate",  # anything you like
            "large_image": "largeimage"  # must match the image key
        }
    }
    print(json.dumps(activity, indent=4))
    rpc_obj.set_activity(activity)
    return json.dumps(f"You sent richPresence Data with this informations : name:{name}, actualDuration:{actualDuration}, totalDuration:{totalDuration}")```

Help please can't start

File "main.py", line 7, in
rpc_obj = rpc.DiscordIpcClient.for_platform(client_id) # Send the client ID to the rpc module
File "/home/container/a/rpc.py", line 52, in for_platform
return UnixDiscordIpcClient(client_id)
File "/home/container/a/rpc.py", line 44, in init
self._do_handshake()
File "/home/container/a/rpc.py", line 59, in _do_handshake
ret_op, ret_data = self.send_recv({'v': 1, 'client_id': self.client_id}, op=OP_HANDSHAKE)
File "/home/container/a/rpc.py", line 107, in send_recv
self.send(data, op)
File "/home/container/a/rpc.py", line 115, in send
self._write(header)
File "/home/container/a/rpc

it get errors by this ll-ll

not showing up on discord

I run the program and everything (i use visual studio code) and it says it all was successful, but when i go back to look and see if it's running it's not running at all, it's not showing me playing anything.

discord-rpc % python3 example.py
Demo for python-discord-rpc Adobe illustrator
RPC connection successful.

thats a direct copy-paste from the terminal (excluding my email and such that it gives on the terminal), how do i fix this??

Randomly crashing because of broken pipe

Hi,

I keep getting a [Errno 32] Broken pipe error randomly. The script runs okay but sometimes randomly after some minutes it crashes with this error:

Traceback (most recent call last):
File "/Users/user/Desktop/folder/folder/script.py", line 27, in
rpc_obj.set_activity(activity)
File "/Users/user/Desktop/folder/folder/rpc.py", line 138, in set_activity
self.send(data)
File "/Users/user/Desktop/folder/folder/rpc.py", line 116, in send
self._write(header)
File "/Users/user/Desktop/folder/folder/rpc.py", line 201, in _write
self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

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.