Skip to content

Commit

Permalink
Refactor act command to support threads
Browse files Browse the repository at this point in the history
  • Loading branch information
MycroftKang committed Sep 26, 2024
1 parent 177c0a8 commit 74b52ff
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/bot/core/controllers/discord/act.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@
@MGCertificate.verify(level=Level.TRUSTED_USERS)
@Feature.Experiment()
async def act(ctx: commands.Context, member: discord.Member, *, message):
webhooks = await ctx.channel.webhooks()
if isinstance(ctx.channel, discord.Thread):
webhooks = await ctx.channel.parent.webhooks()
else:
webhooks = await ctx.channel.webhooks()

if webhooks:
webhook = webhooks[0]
else:
webhook = await ctx.channel.create_webhook(name=member.name)

await webhook.send(
str(message), username=member.display_name, avatar_url=member.avatar.url
)
if isinstance(ctx.channel, discord.Thread):
await webhook.send(
str(message),
thread=ctx.channel,
username=member.display_name,
avatar_url=member.avatar.url,
)
else:
await webhook.send(
str(message), username=member.display_name, avatar_url=member.avatar.url
)

if ctx.interaction:
await ctx.send(
Expand Down

0 comments on commit 74b52ff

Please sign in to comment.