lunarflu HF staff commited on
Commit
bf0c0d3
·
verified ·
1 Parent(s): f1dd6bd

test: keep button functional across bot restarts

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -14,6 +14,8 @@ intents = discord.Intents.all()
14
  bot = commands.Bot(command_prefix="!", intents=intents)
15
  GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
16
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
 
 
17
 
18
  # Dictionary to store user IDs and their corresponding unique strings
19
  user_tokens = {}
@@ -22,6 +24,20 @@ user_tokens = {}
22
  async def on_ready():
23
  print(f'Logged in as {bot.user}')
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def generate_unique_string(length=6):
26
  return secrets.token_hex(length // 2)
27
 
@@ -60,7 +76,7 @@ class DMButton(Button):
60
  async def send_button(ctx):
61
  if ctx.author.id == 811235357663297546:
62
  button = DMButton(label="Verify Discord Account", style=discord.ButtonStyle.primary, user_id=ctx.author.id)
63
- view = View()
64
  view.add_item(button)
65
  await ctx.send("Click the button below to generate your verification link:",view=view) #
66
 
 
14
  bot = commands.Bot(command_prefix="!", intents=intents)
15
  GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
16
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
17
+ BUTTON_CHANNEL_ID = "1106995001155649680"
18
+ BUTTON_MESSAGE_ID = "1266438263531634708"
19
 
20
  # Dictionary to store user IDs and their corresponding unique strings
21
  user_tokens = {}
 
24
  async def on_ready():
25
  print(f'Logged in as {bot.user}')
26
 
27
+ if BUTTON_MESSAGE_ID:
28
+ channel = bot.get_channel(BUTTON_CHANNEL_ID)
29
+ if channel:
30
+ try:
31
+ message = await channel.fetch_message(int(BUTTON_MESSAGE_ID))
32
+ if message:
33
+ view = ButtonView()
34
+ await message.edit(view=view)
35
+ except discord.NotFound:
36
+ print(f"Message with ID {KNOWN_MESSAGE_ID} not found.")
37
+ except discord.HTTPException as e:
38
+ print(f"Failed to fetch message with ID {KNOWN_MESSAGE_ID}: {e}")
39
+
40
+
41
  def generate_unique_string(length=6):
42
  return secrets.token_hex(length // 2)
43
 
 
76
  async def send_button(ctx):
77
  if ctx.author.id == 811235357663297546:
78
  button = DMButton(label="Verify Discord Account", style=discord.ButtonStyle.primary, user_id=ctx.author.id)
79
+ view = ButtonView()
80
  view.add_item(button)
81
  await ctx.send("Click the button below to generate your verification link:",view=view) #
82