-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
import discord
from discord.ext import commands
blue = 0x00ffff
# this should work, please tell me if it did!
ROLE_CATEGORIES = {
"Arts": [
("Studio Art 2D", "AP 2D Art and Design", "<:2DArt:614310804761608207>", 0),
("Studio Art 3D", "AP 3D Art and Design", "<:3DArt:1061485699972464670>", 1),
("Drawing", "AP Drawing", "<:Drawing:1061486284234821743>", 2),
("Art History", "AP Art History", "<:ArtHistory:1061485761960087552>", 0),
("Music Theory", "AP Music Theory", "<:MusicTheory:1061486683201208511>", 1),
],
"English": [
("Literature", "AP English Lit", "<:EnglishLiterature:1061486349015851038>", 0),
("Language", "AP English Lang", "<:EnglishLanguage:1061486335245951086>", 1),
("Seminar", "AP Seminar", "<:Seminar:1061486772825100429>", 0),
("Research", "AP Research", "<:Research:1061486754646990898>", 1),
],
"Languages": [
("Japanese", "AP Japanese", "<:Japanese:1061486555199447040>", 0),
("Italian", "AP Italian", "<:Italian:1061486542369075200>", 0),
("Chinese", "AP Chinese", "<:Chinese:1061486236109394020>", 0),
("Latin", "AP Latin", "<:Latin:1061486569162280990>", 1),
("German", "AP German", "<:German:1061486440904667186>", 1),
("French", "AP French", "<:French:1061486415361347705>", 1),
("Spanish Lang", "AP Spanish Lang", "<:SpanishLanguage:1061486827539795998>", 2),
("Spanish Lit", "AP Spanish Lit", "<:SpanishLiterature:1061486844807762000>", 2),
],
"MathCS": [
("Precalc", "AP Precalculus", "<:precalc:1061804037915279460>", 0),
("Calc AB", "AP Calc AB", "<:CalculusAB:1061486117397995530>", 1),
("Calc BC", "AP Calc BC", "<:CalculusBC:1061486180853616720>", 2),
("Stats", "AP Stats", "<:Statistics:1061486861790482563>", 0),
("Comp Sci A", "AP CompSci A", "<:CSA:1061485898895724615>", 1),
("Comp Sci Prin", "AP CompSci Prin", "<:CSP:1061486067016015892>", 2),
],
"Sciences": [
("Physics 1", "AP Physics 1", "<:Physics1:1061486700485955644>", 0),
("Physics 2", "AP Physics 2", "<:Physics2:1061486719960096890>", 1),
("Chemistry", "AP Chem", "<:Chemistry:1061486200810131476>", 2),
("Mech", "AP Physics C Mech", "<:Mechanics:1061486622446731354>", 0),
("E/M", "AP Physics C E/M", "<:EM:1061486300995268658>", 1),
("Enviro", "AP Environ Sci", "<:EnvironmentalScience:1061486372541698099>", 0),
("Biology", "AP Biology", "<:Biology:1061485856868794368>", 1),
],
"SocialStudies": [
("Comp Gov", "AP Comparative Government", "<:ComparativeGovernment:1061486253192781865>", 0),
("World M", "AP World History: Modern", "<:ModernWorldHistory:1061486662284222525>", 1),
("Human Geo", "AP Human Geo", "<:HumanGeography:1061486512585314325>", 2),
("US Gov", "AP US Gov", "<:USGovernment:1061486879884722206>", 0),
("APUSH", "AP US History", "<:USHistory:1061486902903054386>", 1),
("Micro", "AP Micro", "<:Microeconomics:1061486644559089724>", 2),
("Psych", "AP Psych", "<:Psychology:1061486737857183774>", 0),
("Euro", "AP Euro", "<:EuropeanHistory:1061486395455180832>", 1),
("Macro", "AP Macro", "<:Macroeconomics:1061486600267251732>", 2),
],
"PostAP": [
("Post-AP Math", "Post-AP Math", "<:postapmath:1061801588508872794>", 0),
("Higher CS", "Higher CS", "<:highercs:1061801585312804924>", 1),
("Higher Other", "Higher Other", "<:higherother:1061801586453643265>", 2),
],
"Pronouns": [
("she/her", "she/her/hers", "<:sheher:1061486974055227492>", 0),
("he/him", "he/him/his", "<:hehim:1061486951875760241>", 1),
("they/them", "they/them/theirs", "<:theythem:1061486997576892416>", 0),
("Ask me!", "Ask me for my pronouns!", "<:askme:1061803381804507257>", 1),
],
"Booster": [
("nitro-a", "nitro-a", None, 0),
("nitro-b", "nitro-b", None, 1),
("nitro-c", "nitro-c", None, 2),
("nitro-d", "nitro-d", None, 0),
("nitro-e", "nitro-e", None, 1),
("nitro-f", "nitro-f", None, 2),
],
"LoungeOne": [
("Anime-Manga", "Lounge: Anime & Manga", "🍡", 0),
("Art", "Lounge: Art", "🖌", 1),
("Books-Writing", "Lounge: Books & Writing", "📚", 2),
("Events", "Lounge: Events", "🎉", 0),
("Fashion", "Lounge: Fashion", "👓", 1),
("Film-TV", "Lounge: Film & TV", "📽", 2),
],
"LoungeTwo": [
("Food", "Lounge: Food", "🥘", 0),
("Gaming", "Lounge: Gaming", "🎮", 1),
("Languages", "Lounge: Languages", "🌐", 2),
("Music", "Lounge: Music", "🎵", 0),
("Pets", "Lounge: Pets", "🐱", 1),
("Photography", "Lounge: Photography", "📷", 2),
],
"LoungeThree": [
("Sports", "Lounge: Sports", "🏀", 0),
("Tech", "Lounge: Tech", "🖥️", 0),
("Opt-Out of Lounge", "Lounge: Opt-Out", None, 1, discord.ButtonStyle.red),
],
}
def create_view(category, bot):
class GenericView(discord.ui.View):
def __init__(self, bot):
super().__init__(timeout=None)
self.bot = bot
# Dynamically add buttons
for idx, role_data in enumerate(ROLE_CATEGORIES[category]):
label, role_name, emoji, row, *style = role_data
button_style = style[0] if style else discord.ButtonStyle.grey
async def callback(self, interaction, button, role_name=role_name, booster=(category=="Booster")):
guild = interaction.guild
member = guild.get_member(interaction.user.id)
role = discord.utils.get(guild.roles, name=role_name)
if role:
if role in member.roles:
await member.remove_roles(role)
await interaction.response.send_message(f"`{role.name}` role removed!", ephemeral=True)
else:
if booster:
for role_check in member.roles:
if "nitro" in role_check.name:
await member.remove_roles(role_check)
await member.add_roles(role)
await interaction.response.send_message(f"`{role.name}` role added!", ephemeral=True)
kwargs = dict(label=label, style=button_style, custom_id=label, row=row)
if emoji: kwargs['emoji'] = emoji
setattr(GenericView, f"button_{idx}", discord.ui.button(**kwargs)(callback))
return GenericView(bot)
class RoleReact(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
async def setup(bot):
await bot.add_cog(RoleReact(bot), guilds=[discord.Object(id=bot.guild_id)])
for category in ROLE_CATEGORIES:
bot.add_view(create_view(category, bot))
Please tell me if it worked :) It should make it less clumped
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels