Fix: Improve Nitro check for giveaways

Make `is_user_nitro_like` an async function to fetch full user objects, enabling banner checks for Nitro detection. Pass the bot instance to the function for this purpose.
This commit is contained in:
Slipstream 2025-05-30 17:19:06 -06:00
parent a3bf678b32
commit b605138d04
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -14,8 +14,16 @@ GIVEAWAY_DATA_FILE = "data/giveaways.json"
DATA_DIR = "data"
# --- Helper Functions ---
def is_user_nitro_like(user: discord.User | discord.Member) -> bool:
async def is_user_nitro_like(user: discord.User | discord.Member, bot: commands.Bot = None) -> bool:
"""Checks if a user has an animated avatar or a banner, indicating Nitro."""
# Fetch the full user object to get banner information
if bot:
try:
fetched_user = await bot.fetch_user(user.id)
user = fetched_user
except discord.NotFound:
pass # Use the original user object if fetch fails
if isinstance(user, discord.Member): # Member object has guild-specific avatar
# Check guild avatar first, then global avatar
if user.guild_avatar and user.guild_avatar.is_animated():
@ -43,7 +51,7 @@ class GiveawayEnterButton(ui.Button['GiveawayEnterView']):
return
if giveaway["is_nitro_giveaway"]:
if not is_user_nitro_like(interaction.user):
if not await is_user_nitro_like(interaction.user, bot=self.cog.bot):
await interaction.response.send_message(
"This is a Nitro-exclusive giveaway. You don't appear to have Nitro (animated avatar or banner).",
ephemeral=True