Created command to clear table messages.
This commit is contained in:
@@ -24,6 +24,38 @@ class MessageManagement(commands.Cog, name="Message Management"):
|
|||||||
"""
|
"""
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
@nextcord.slash_command(
|
||||||
|
description="Clears highscores channel of all table messages. Does not change data.",
|
||||||
|
default_member_permissions=nextcord.Permissions(administrator=True),
|
||||||
|
)
|
||||||
|
async def delete_table_messages(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
"""
|
||||||
|
Deletes all table messages from highscores channel. Does not change data.
|
||||||
|
Does not delete highscores channel id.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||||
|
"""
|
||||||
|
guild = highscores_data.get_guild(interaction.guild_id)
|
||||||
|
|
||||||
|
highscores_channel: nextcord.TextChannel = interaction.guild.get_channel(
|
||||||
|
guild.highscore_channel
|
||||||
|
)
|
||||||
|
|
||||||
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
|
for table in guild.tables:
|
||||||
|
try:
|
||||||
|
table_message: nextcord.Message = await highscores_channel.fetch_message(
|
||||||
|
table.message_id
|
||||||
|
)
|
||||||
|
await table_message.delete()
|
||||||
|
except nextcord.NotFound:
|
||||||
|
# silently ignore that messages are not found. They got deleted already.
|
||||||
|
pass
|
||||||
|
|
||||||
|
await interaction.send("Table messages deleted.", ephemeral=True)
|
||||||
|
|
||||||
@nextcord.slash_command(
|
@nextcord.slash_command(
|
||||||
description="Triggers post/update of highscores to registered highscore channel.",
|
description="Triggers post/update of highscores to registered highscore channel.",
|
||||||
default_member_permissions=nextcord.Permissions(administrator=True),
|
default_member_permissions=nextcord.Permissions(administrator=True),
|
||||||
@@ -53,7 +85,7 @@ class MessageManagement(commands.Cog, name="Message Management"):
|
|||||||
error_response = "No tables have been created for this guild. Please create some tables."
|
error_response = "No tables have been created for this guild. Please create some tables."
|
||||||
assert (
|
assert (
|
||||||
len(highscores_data.get_guild(interaction.guild_id).tables) > 0
|
len(highscores_data.get_guild(interaction.guild_id).tables) > 0
|
||||||
), await interaction.response(error_response, ephemeral=True)
|
), await interaction.send(error_response, ephemeral=True)
|
||||||
|
|
||||||
# awaiting response because posting scores takes a while
|
# awaiting response because posting scores takes a while
|
||||||
await interaction.response.defer(ephemeral=True)
|
await interaction.response.defer(ephemeral=True)
|
||||||
@@ -66,4 +98,4 @@ class MessageManagement(commands.Cog, name="Message Management"):
|
|||||||
# messages have been sent.
|
# messages have been sent.
|
||||||
highscores_data.save_guild_data(guild)
|
highscores_data.save_guild_data(guild)
|
||||||
|
|
||||||
await interaction.followup.send(f"Posted all tables to <#{channel.id}>.", ephemeral=True)
|
await interaction.send(f"Posted all tables to <#{channel.id}>.", ephemeral=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user