-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_teams.py
More file actions
51 lines (38 loc) · 1.23 KB
/
build_teams.py
File metadata and controls
51 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import discord
from discord.ext import commands, tasks
import schedule
from pytz import timezone
import asyncio
import os
from dotenv import load_dotenv
import random
load_dotenv()
intents = discord.Intents.default()
intents.reactions = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}')
schedule.every(2).weeks.friday.at("22:00", timezone('America/Mexico_City')).do(create_teams)
async def create_teams():
message_id = 12421
channel_id = os.getenv('CHANNEL_ID')
team_sz = 3
channel = bot.get_channel(channel_id)
message = await channel.fetch_message(message_id)
reactions = message.reactions
users = []
for reaction in reactions:
async for user in reaction.users():
users.append(user)
random.shuffle(users)
teams = [users[i:i + team_sz] for i in range(0, len(users), team_sz)]
for i, team in enumerate(teams):
team_str = ', '.join([user.name for user in team])
await channel.send(f'Team {i + 1}: {team_str}')
async def run_schedule():
while True:
schedule.run_pending()
await asyncio.sleep(1)
bot.loop.create_task(run_schedule())
bot.run(os.getenv('BOT_TOKEN'))