diff options
| -rw-r--r-- | bot/exts/filtering/_settings_types/actions/infraction_and_notification.py | 7 | ||||
| -rw-r--r-- | bot/exts/filtering/_ui/ui.py | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py b/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py index ed08362de..d60bcac5b 100644 --- a/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py +++ b/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py @@ -5,6 +5,7 @@ from typing import ClassVar import arrow import discord.abc from botcore.utils.logging import get_logger +from botcore.utils.members import get_or_fetch_member from discord import Colour, Embed, Member, User from discord.errors import Forbidden from pydantic import validator @@ -37,7 +38,7 @@ class Infraction(Enum): async def invoke( self, user: Member | User, - channel: discord.abc.Messageable, + channel: discord.abc.GuildChannel | discord.DMChannel, alerts_channel: discord.TextChannel, duration: float, reason: str @@ -50,6 +51,10 @@ class Infraction(Enum): log.warning(f":warning: Could not apply {command_name} to {user.mention}: command not found.") return + if isinstance(user, discord.User): # For example because a message was sent in a DM. + member = await get_or_fetch_member(channel.guild, user.id) + if member: + user = member ctx = FakeContext(channel, command) if self.name in ("KICK", "WARNING", "WATCH", "NOTE"): await command(ctx, user, reason=reason or None) diff --git a/bot/exts/filtering/_ui/ui.py b/bot/exts/filtering/_ui/ui.py index e71bab0d1..98741a96d 100644 --- a/bot/exts/filtering/_ui/ui.py +++ b/bot/exts/filtering/_ui/ui.py @@ -11,6 +11,7 @@ import discord from botcore.site_api import ResponseCodeError from botcore.utils import scheduling from botcore.utils.logging import get_logger +from botcore.utils.members import get_or_fetch_member from discord import Embed, Interaction from discord.ext.commands import Context from discord.ui.select import MISSING as SELECT_MISSING, SelectOption @@ -529,7 +530,11 @@ class AlertView(discord.ui.View): await interaction.response.defer() fake_ctx = FakeContext(interaction.channel, command, author=interaction.user) - await command(fake_ctx, self.ctx.author) + # Get the most updated user/member object every time the button is pressed. + author = await get_or_fetch_member(interaction.guild, self.ctx.author.id) + if author is None: + author = await bot.instance.fetch_user(self.ctx.author.id) + await command(fake_ctx, author) @discord.ui.button(emoji="⚠") async def user_infractions(self, interaction: Interaction, button: discord.ui.Button) -> None: |