Skip to content

Commit ab6da36

Browse files
tuff
1 parent 4cf7d68 commit ab6da36

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

cogs/model_management_cog.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,24 @@ async def modgetmodel(self, ctx: commands.Context):
181181
@byok.command(name="set", description="Set the guild's API key for a specific provider.")
182182
@app_commands.checks.has_permissions(administrator=True)
183183
@app_commands.describe(provider="The provider to set the key for (e.g., 'openai', 'anthropic').")
184-
async def byok_set(self, interaction: discord.Interaction, provider: str):
184+
async def byok_set(self, ctx: commands.Context, provider: str):
185185
"""Sets the guild's API key via a modal."""
186-
modal = ApiKeyModal(
187-
title=f"Set API Key for {provider}",
188-
provider=provider,
189-
guild_id=interaction.guild.id,
190-
)
191-
await interaction.response.send_modal(modal)
186+
# Check if this is a slash command (has interaction) or text command
187+
if ctx.interaction:
188+
# Slash command - can use modal
189+
modal = ApiKeyModal(
190+
title=f"Set API Key for {provider}",
191+
provider=provider,
192+
guild_id=ctx.guild.id,
193+
)
194+
await ctx.interaction.response.send_modal(modal)
195+
else:
196+
# Text command - cannot use modal, inform user to use slash command
197+
await ctx.send(
198+
"⚠️ This command requires the use of a secure modal for API key input. "
199+
"Please use the slash command version: `/byok set` instead of the text command.",
200+
ephemeral=False,
201+
)
192202

193203
@byok.command(
194204
name="info",
@@ -241,10 +251,20 @@ async def byok_copilot_login(self, ctx: commands.Context):
241251
description="Set the guild's OpenRouter API key for AI moderation.",
242252
)
243253
@app_commands.checks.has_permissions(administrator=True)
244-
async def byok_openrouter(self, interaction: discord.Interaction):
254+
async def byok_openrouter(self, ctx: commands.Context):
245255
"""Sets the guild's OpenRouter API key via a secure modal."""
246-
modal = OpenRouterApiKeyModal(guild_id=interaction.guild.id)
247-
await interaction.response.send_modal(modal)
256+
# Check if this is a slash command (has interaction) or text command
257+
if ctx.interaction:
258+
# Slash command - can use modal
259+
modal = OpenRouterApiKeyModal(guild_id=ctx.guild.id)
260+
await ctx.interaction.response.send_modal(modal)
261+
else:
262+
# Text command - cannot use modal, inform user to use slash command
263+
await ctx.send(
264+
"⚠️ This command requires the use of a secure modal for API key input. "
265+
"Please use the slash command version: `/byok openrouter` instead of the text command.",
266+
ephemeral=False,
267+
)
248268

249269

250270
async def setup(bot: commands.Bot):

0 commit comments

Comments
 (0)