Skip to content

Instantly share code, notes, and snippets.

@Luc1412
Created December 25, 2023 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luc1412/95f46d65703bb00110fcc3e7d0fd4a1f to your computer and use it in GitHub Desktop.
Save Luc1412/95f46d65703bb00110fcc3e7d0fd4a1f to your computer and use it in GitHub Desktop.
Christmas Giveaway Code
import random
import orjson
import io
# Get the Giveaway message and all users that reacted and are still on the server
msg = await bot.get_channel(1183749648880504962).fetch_message(1183849922441773077)
reaction = discord.utils.get(msg.reactions, emoji='🎁')
user_ids = [u.id async for u in reaction.users(limit=None) if guild.get_member(u.id)]
# Check for users that are eligable
session = aiohttp.ClientSession()
entries = []
for user_id in user_ids:
async with session.get(f'https://api.easyfnstats.com/giveaway?user_id={user_id}') as resp:
data = await resp.json()
count = data['entries'] # 1 = User Linked their Account | 2 = User also check the locker
if not count:
continue
entries.extend([user_id] * (count + 1)) # 2 Entries for normal users, 50% more entries (3) if users check their locker
# Choose the winners and remove them from the entries
winner_ids = []
for i in range(10):
user_id = random.choice(entries)
entries = [u for u in entries if u != user_id]
winner_ids.append(user_id)
# Send the results
winners_fmt = [f'{i}. **{guild.get_member(uid)}**' for i, uid in enumerate(winner_ids, start=1)]
embed = discord.Embed(colour=0x7BD3EA)
embed.description = f'# Giveaway Results\n{len(set(entries))} users successfully entered the giveaway. All winners will be contacted in a private thread and need to respond until <t:1703703600>.\n### Winners:\n' + '\n'.join(winners_fmt)
await ctx.bot.get_channel(1183749648880504962).send(embed=embed)
# Save the list of remaining entries for a reroll
await ctx.send(file=discord.File(io.BytesIO(orjson.dumps(entries)), filename='entries.json'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment