Spaces:
Running on CPU Upgrade

lunarflu HF Staff commited on
Commit
d0b459f
·
verified ·
1 Parent(s): 2deada4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -52,6 +52,9 @@ bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 113077
52
  hf_token = os.environ.get("HF_TOKEN")
53
 
54
 
 
 
 
55
  class DMButton(Button):
56
  def __init__(self, label, style):
57
  super().__init__(label=label, style=style)
@@ -101,7 +104,11 @@ async def on_ready():
101
 
102
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
103
  def run_bot():
104
- bot.run(DISCORD_TOKEN)
 
 
 
 
105
  threading.Thread(target=run_bot).start()
106
 
107
 
@@ -132,7 +139,9 @@ def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
132
  else:
133
  print(f"⚠️ {member.name} did not have the pending role. Ignoring.")
134
 
135
- asyncio.create_task(upgrade_role())
 
 
136
  return f"# ✅ Verification successful! Welcome, {profile.username} 🎉"
137
 
138
 
 
52
  hf_token = os.environ.get("HF_TOKEN")
53
 
54
 
55
+ discord_loop = None # global variable
56
+
57
+
58
  class DMButton(Button):
59
  def __init__(self, label, style):
60
  super().__init__(label=label, style=style)
 
104
 
105
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
106
  def run_bot():
107
+ global discord_loop
108
+ discord_loop = asyncio.new_event_loop()
109
+ asyncio.set_event_loop(discord_loop)
110
+ discord_loop.create_task(bot.start(DISCORD_TOKEN))
111
+ discord_loop.run_forever()
112
  threading.Thread(target=run_bot).start()
113
 
114
 
 
139
  else:
140
  print(f"⚠️ {member.name} did not have the pending role. Ignoring.")
141
 
142
+ global discord_loop
143
+ if discord_loop:
144
+ asyncio.run_coroutine_threadsafe(upgrade_role(), discord_loop)
145
  return f"# ✅ Verification successful! Welcome, {profile.username} 🎉"
146
 
147