Skip to content

Commit

Permalink
Delete message after user selection
Browse files Browse the repository at this point in the history
This is to prevent users from sending too many messages.
  • Loading branch information
MasterJ93 committed Nov 27, 2023
1 parent c4d1ee6 commit ab424e0
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions views/beginner_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains views related to members that just came into the server.
"""
import asyncio
import discord

from config import settings
Expand Down Expand Up @@ -61,7 +62,7 @@ async def selection_1(self,
view=view
)

await self.send_message_and_end_onboarding(interaction.response,
await self.send_message_and_end_onboarding(interaction,
response_message)

@discord.ui.button(
Expand All @@ -81,7 +82,7 @@ async def selection_2(self,
billboards=self.alliance_billboard.mention
)

await self.send_message_and_end_onboarding(interaction.response,
await self.send_message_and_end_onboarding(interaction,
response_message)

@discord.ui.button(
Expand All @@ -99,25 +100,37 @@ async def selection_3(self,

response_message = beginner['OPTION_3_RESPONSE']

await self.send_message_and_end_onboarding(interaction.response,
await self.send_message_and_end_onboarding(interaction,
response_message)

async def send_message_and_end_onboarding(
self,
response: discord.InteractionResponse,
interaction: discord.Interaction,
response_message: str):
"""
Sends an ephemeral message, then finds and deletes the
original message.
"""

# Ephemeral message is sent, then is deleted after a minute.
await response.send_message(
await interaction.response.send_message(
content=response_message,
ephemeral=True,
delete_after=60.0
)

message_counter = 3
async for message in \
interaction.channel.history(limit=200): #type: ignore
if message.author.bot is True:
await message.delete()
await asyncio.sleep(3)
message_counter -= 1

if message_counter == 0:
break


class ClanInviteInterestView(discord.ui.View):
"""
Contains a view for admins to decide whether to
Expand Down

0 comments on commit ab424e0

Please sign in to comment.