Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadock-is-ok committed Dec 9, 2023
1 parent 7ee3f3a commit 166e6f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def send(
return await super().send(content, **kwargs)

if add_button_view:
delete_button = DeleteView(self).children[0]
delete_button = DeleteView(self.author.id).children[0]
original_view = kwargs.get("view") or discord.ui.View()
if original_view:
original_view.add_item(delete_button)
Expand Down
8 changes: 4 additions & 4 deletions utils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@


class DeleteView(discord.ui.View):
def __init__(self, ctx: AloneContext) -> None:
def __init__(self, author_id: int) -> None:
super().__init__(timeout=None)
self.ctx: AloneContext = ctx
self.author_id: int = author_id

@discord.ui.button(
emoji="\U0001f5d1",
Expand All @@ -22,14 +22,14 @@ def __init__(self, ctx: AloneContext) -> None:
custom_id="delete",
)
async def delete(self, interaction: discord.Interaction, _) -> None:
if interaction.user.id == self.ctx.author.id:
if interaction.user.id == self.author_id:
if not interaction.message:
return

return await interaction.message.delete()

await interaction.response.send_message(
f"This command was ran by {self.ctx.author.name}, so you can't delete it!",
f"This command was ran by <@{self.author_id}>, so you can't delete it!",
ephemeral=True,
)

Expand Down

0 comments on commit 166e6f8

Please sign in to comment.