-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroups.py
More file actions
66 lines (54 loc) · 2.07 KB
/
groups.py
File metadata and controls
66 lines (54 loc) · 2.07 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import discord
from discord import app_commands
from discord.ext import commands
class GROUPS(commands.Cog, description="Group Finding"):
def __init__(self, bot):
self.bot = bot
@app_commands.command(name="find_group", description="Find a study group")
async def find_group(self, interaction: discord.Interaction):
if not interaction.guild:
await interaction.response.send_message(
"This command can only be used in a server.",
ephemeral=True,
delete_after=5,
)
return
open_group_role = discord.utils.get(interaction.guild.roles, name="Open Group")
no_group_role = discord.utils.get(interaction.guild.roles, name="No Group")
if not open_group_role or not no_group_role:
await interaction.response.send_message(
"Role(s) not found. Is this the right server?",
ephemeral=True,
delete_after=5,
)
return
# Get all users with the open group role
members_with_open_role = [
member
for member in interaction.guild.members
if open_group_role in member.roles
]
# Get all users with the no group role
members_with_no_group_role = [
member
for member in interaction.guild.members
if no_group_role in member.roles
]
embed = discord.Embed(
title="Groups", colour=0x00B0F4
)
embed.add_field(
name="Open Group",
value="\n".join(member.mention for member in members_with_open_role)[:1000]
or "No users found.",
inline=False,
)
embed.add_field(
name="No Group",
value="\n".join(member.mention for member in members_with_no_group_role)[:1000]
or "No users found.",
inline=False,
)
await interaction.response.send_message(embed=embed, ephemeral=True)
async def setup(bot: commands.Bot):
await bot.add_cog(GROUPS(bot))