more autocomplete

Kaveen Kumarasinghe 2 years ago
parent ca0fa419f9
commit e947e030fb

@ -175,6 +175,7 @@ class Commands(discord.Cog, name="Commands"):
name="alert_channel_id",
description="The channel ID to send moderation alerts to",
required=False,
autocomplete=Settings_autocompleter.get_value_alert_id_channel
)
@discord.guild_only()
async def moderations(
@ -191,8 +192,8 @@ class Commands(discord.Cog, name="Commands"):
@discord.option(
name="type",
description="The type of moderation to configure",
choices=["warn", "delete"],
required=True,
autocomplete=Settings_autocompleter.get_value_moderations,
)
@discord.option(
name="hate",

@ -147,6 +147,14 @@ class ModerationsService(discord.Cog, name="ModerationsService"):
'''command handler for toggling moderation and setting an alert channel'''
await ctx.defer()
try:
if alert_channel_id:
int(alert_channel_id)
except ValueError:
# the alert_channel_id was passed in as a channel NAME instead of an ID, fetch the ID.
alert_channel = discord.utils.get(ctx.guild.channels, name=alert_channel_id)
alert_channel_id = alert_channel.id
if status == "on":
# Check if the current guild is already in the database and if so, if the moderations is on
if self.check_guild_moderated(ctx.guild_id):

@ -42,6 +42,7 @@ class Settings_autocompleter:
"num_static_conversation_items": [str(num) for num in range(5, 20 + 1)],
"num_conversation_lookback": [str(num) for num in range(5, 15 + 1)],
"summarize_threshold": [str(num) for num in range(800, 3500, 50)],
"type": ["warn", "delete"],
}
for parameter in values:
if parameter == ctx.options["parameter"]:
@ -53,6 +54,26 @@ class Settings_autocompleter:
await ctx.interaction.response.defer() # defer so the autocomplete in int values doesn't error but rather just says not found
return []
async def get_value_moderations(
ctx: discord.AutocompleteContext,
): # Behaves a bit weird if you go back and edit the parameter without typing in a new command
'''gets valid values for the type option'''
print(f"The value is {ctx.value}")
return [
value
for value in ["warn", "delete"]
if value.startswith(ctx.value.lower())
]
async def get_value_alert_id_channel(self, ctx: discord.AutocompleteContext):
'''gets valid values for the channel option'''
return [
channel.name
for channel in ctx.interaction.guild.channels
if channel.name.startswith(ctx.value.lower())
]
class File_autocompleter:
'''Autocompleter for the opener command'''

Loading…
Cancel
Save