diff --git a/DOCS.md b/DOCS.md
index d66c334..e808e8e 100644
--- a/DOCS.md
+++ b/DOCS.md
@@ -79,7 +79,7 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https:
Parameters :
- state (`str`)
- details (`str`)
- - act_type (`int`) : [Activity Types](https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-types) (Activity Type `1` and `4` is currently disabled, see [#28](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)).
+ - act_type (`discordrpc.Activity`) : [Activity Types](https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-types) (Activity Type `1` and `4` is currently disabled, see [#28](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)).
- ts_start (`int`) : Timestamp start.
- ts_end (`int`) : Timestamp end.
- large_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal.
@@ -122,6 +122,23 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https:
Return : `True` or `False`
+## class `discordrpc.Activity`
+- Enum `Activity`
+ Simplified Activity type payload in `RPC.set_activity`
+
+ Available values :
+ - Playing
+ - Streaming
+ - Listening
+ - Watching
+ - Custom
+ - Competing
+
+> [!NOTE]
+> Activity Type `Streaming` and `Custom` currently disabled.
+> [Details](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)
+
+
## class `discordrpc.Button()`
- function `Button()`
Simplified button payload in `RPC.set_activity`
diff --git a/discordrpc/__init__.py b/discordrpc/__init__.py
index 9cb6ee3..e8598b3 100644
--- a/discordrpc/__init__.py
+++ b/discordrpc/__init__.py
@@ -1,6 +1,7 @@
from .presence import RPC
from .button import Button
from .exceptions import *
+from .types import *
from .utils import timestamp, date_to_timestamp
__title__ = "Discord RPC"
diff --git a/discordrpc/exceptions.py b/discordrpc/exceptions.py
index 1d8f3da..740152e 100644
--- a/discordrpc/exceptions.py
+++ b/discordrpc/exceptions.py
@@ -28,7 +28,11 @@ class ButtonError(RPCException):
def __init__(self, message: str = None):
super().__init__(message=message)
-# https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350
class InvalidActivityType(RPCException):
+ def __init__(self, message):
+ super().__init__(f"Activity type must be , not {message}")
+
+# https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350
+class ActivityTypeDisabled(RPCException):
def __init__(self):
super().__init__(f"Activity Type 1 and 4 currently disabled. See https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350")
\ No newline at end of file
diff --git a/discordrpc/presence.py b/discordrpc/presence.py
index fba93b3..b942eb3 100644
--- a/discordrpc/presence.py
+++ b/discordrpc/presence.py
@@ -6,6 +6,7 @@
import uuid
import re
from .exceptions import *
+from .types import *
from .utils import remove_none
import logging
import time
@@ -55,7 +56,7 @@ def _setup(self):
def set_activity(
self,
- state: str=None, details:str=None, act_type:int=0,
+ state: str=None, details:str=None, act_type:Activity=Activity.Playing,
ts_start:int=None, ts_end:int=None,
large_image:str=None, large_text:str=None,
small_image:str=None, small_text:str=None,
@@ -67,15 +68,17 @@ def set_activity(
if type(party_id) == int:
party_id = str(party_id)
+ if type(act_type) != Activity:
+ raise InvalidActivityType(type(act_type))
+
# https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350
- invalidType = ["1", "4"]
- if any(invtype in str(act_type) for invtype in invalidType):
+ if act_type in [Activity.Streaming, Activity.Custom]:
raise InvalidActivityType()
act = {
"state": state,
"details": details,
- "type": act_type,
+ "type": act_type.value,
"timestamps": {
"start": ts_start,
"end": ts_end
diff --git a/discordrpc/types.py b/discordrpc/types.py
new file mode 100644
index 0000000..6cad739
--- /dev/null
+++ b/discordrpc/types.py
@@ -0,0 +1,11 @@
+from enum import Enum
+
+
+# https://discord.com/developers/docs/events/gateway-events#activity-object-activity-types
+class Activity(Enum):
+ Playing = 0
+ Streaming = 1
+ Listening = 2
+ Watching = 3
+ Custom = 4
+ Competing = 5
diff --git a/examples/rpc-with-activitytype.py b/examples/rpc-with-activitytype.py
new file mode 100644
index 0000000..da30c87
--- /dev/null
+++ b/examples/rpc-with-activitytype.py
@@ -0,0 +1,21 @@
+import discordrpc
+from discordrpc import Activity
+import time
+
+
+rpc = discordrpc.RPC(app_id=123456789)
+
+
+current_time = int(time.time())
+finish_time = current_time + 200
+
+rpc.set_activity(
+ state="With activity type",
+ details="Music",
+ act_type=Activity.Listening,
+ ts_start=current_time,
+ ts_end=finish_time
+)
+
+
+rpc.run()