roles
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
.env
|
||||||
|
.venv
|
||||||
|
__pycache__
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
import discord, os, views
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
|
||||||
|
load_dotenv() # load all the variables from the env file
|
||||||
|
bot = discord.Bot()
|
||||||
|
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_ready():
|
||||||
|
bot.add_view(views.RoleSelectors())
|
||||||
|
print(f"{bot.user} is ready and online!")
|
||||||
|
|
||||||
|
|
||||||
|
@bot.slash_command(name="role_selector", description="create role selector")
|
||||||
|
async def species(ctx: discord.ApplicationContext):
|
||||||
|
await ctx.respond("Role selector menu", view=views.RoleSelectors())
|
||||||
|
|
||||||
|
|
||||||
|
bot.run(os.getenv('TOKEN')) # run the bot with the token
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import discord
|
||||||
|
|
||||||
|
|
||||||
|
async def PlatformCallback(interaction: discord.Interaction, values: list):
|
||||||
|
for platform in ["PC", "Xbox", "Playstation", "Nintendo", "VR"]:
|
||||||
|
if not discord.utils.get(interaction.guild.roles, name=platform):
|
||||||
|
await interaction.guild.create_role(name=platform, color=discord.Color.random())
|
||||||
|
|
||||||
|
if platform not in values:
|
||||||
|
await interaction.user.remove_roles(discord.utils.get(interaction.guild.roles, name=platform))
|
||||||
|
|
||||||
|
for platform in values:
|
||||||
|
await interaction.user.add_roles(discord.utils.get(interaction.guild.roles, name=platform))
|
||||||
|
|
||||||
|
embed = discord.Embed(title="Platform Roles Updated")
|
||||||
|
embed.add_field(name="Selected Platforms", value=", ".join(values))
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
async def SpeciesCallback(interaction: discord.Interaction, value: str):
|
||||||
|
species_list = [species.strip().capitalize() for species in value.split(",")]
|
||||||
|
|
||||||
|
for species in species_list:
|
||||||
|
if not discord.utils.get(interaction.guild.roles, name=species):
|
||||||
|
await interaction.guild.create_role(name=species, color=discord.Color.random())
|
||||||
|
|
||||||
|
await interaction.user.add_roles(discord.utils.get(interaction.guild.roles, name=species))
|
||||||
|
|
||||||
|
embed = discord.Embed(title="Species Roles Updated")
|
||||||
|
embed.add_field(name="Selected Species", value=", ".join(species_list))
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import discord, roles
|
||||||
|
|
||||||
|
|
||||||
|
# Platform Role Select View
|
||||||
|
class Platforms(discord.ui.View):
|
||||||
|
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
|
||||||
|
placeholder = "Select Platforms", # the placeholder text that will be displayed if nothing is selected
|
||||||
|
min_values = 1, # the minimum number of values that must be selected by the users
|
||||||
|
max_values = 5, # the maximum number of values that can be selected by the users
|
||||||
|
options = [ # the list of options from which users can choose, a required field
|
||||||
|
discord.SelectOption(
|
||||||
|
label="PC",
|
||||||
|
description="pcmr"
|
||||||
|
),
|
||||||
|
discord.SelectOption(
|
||||||
|
label="Xbox",
|
||||||
|
description="microslop"
|
||||||
|
),
|
||||||
|
discord.SelectOption(
|
||||||
|
label="Playstation",
|
||||||
|
description="idk what to put here"
|
||||||
|
),
|
||||||
|
discord.SelectOption(
|
||||||
|
label="Nintendo",
|
||||||
|
description="who actually uses this"
|
||||||
|
),
|
||||||
|
discord.SelectOption(
|
||||||
|
label="VR",
|
||||||
|
description="vrchat"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
|
||||||
|
await roles.PlatformCallback(interaction, select.values)
|
||||||
|
|
||||||
|
|
||||||
|
# Species Role View
|
||||||
|
class Species(discord.ui.Modal):
|
||||||
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.add_item(discord.ui.InputText(label="Enter Species (comma seperated for multiple)"))
|
||||||
|
|
||||||
|
async def callback(self, interaction: discord.Interaction):
|
||||||
|
await roles.SpeciesCallback(interaction, self.children[0].value)
|
||||||
|
|
||||||
|
|
||||||
|
# Role selectors view
|
||||||
|
class RoleSelectors(discord.ui.View):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
|
@discord.ui.button(label="Species", custom_id="species", style=discord.ButtonStyle.primary)
|
||||||
|
async def species_button_callback(self, button, interaction):
|
||||||
|
await interaction.response.send_modal(Species(title="Choose your species"))
|
||||||
|
|
||||||
|
@discord.ui.button(label="Platform", custom_id="platform", style=discord.ButtonStyle.primary)
|
||||||
|
async def platform_button_callback(self, button, interaction):
|
||||||
|
await interaction.response.send_message("Choose your platforms", view=Platforms(), ephemeral=True)
|
||||||
Reference in New Issue
Block a user