I am a beginner to Python and recently was making a **Discord Rich Prescense** application. The problem is that I was using a While Loop and added a “*Press Enter to Exit*” feature. This made the Rich Prescense stuck on One Quote. I have attached a screenshot of the problem.
JavaScript
x
17
17
1
from config import credentials
2
from data import quotes
3
from pypresence import Presence
4
import random
5
import time
6
7
def quotegen():
8
RPC = Presence(credentials.clientid)
9
RPC.connect()
10
11
while True:
12
RPC.update(details="Random Quote:", state=random.choice(quotes.quotes))
13
i = input("Press Enter to Exit")
14
time.sleep(30)
15
if not i:
16
break
17
Screenshot of what its supposed to do:
Advertisement
Answer
Using the keyboard module (https://pypi.org/project/keyboard/) you can do it all.
I modified your code to fit your requirements:
JavaScript
1
18
18
1
import keyboard # using module keyboard
2
from config import credentials
3
from data import quotes
4
from pypresence import Presence
5
import random
6
import time
7
8
def quotegen():
9
RPC = Presence(credentials.clientid)
10
RPC.connect()
11
12
while True:
13
RPC.update(details="Random Quote:", state=random.choice(quotes.quotes))
14
i = input("Press Enter to Exit")
15
time.sleep(30)
16
if keyboard.is_pressed('enter'): # if key 'enter' is pressed
17
break
18