Create persistent buttons for role selection prompt
This commit is contained in:
parent
dc7e141756
commit
d84845b79e
30
main.py
30
main.py
|
@ -9,15 +9,22 @@ from discord.ext.commands import Greedy, Context
|
|||
from discord import app_commands
|
||||
|
||||
from src.roles import AddRoleButton, RemoveRoleButton
|
||||
from src.ui import RoleSelectView
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=",", intents=discord.Intents.default())
|
||||
self.intents.message_content = True
|
||||
|
||||
async def setup_hook(self) -> None:
|
||||
self.add_view(RoleSelectView())
|
||||
return await super().setup_hook()
|
||||
|
||||
with open('config.yaml', 'r') as file:
|
||||
config = safe_load(file)
|
||||
|
||||
# Bot
|
||||
intents=discord.Intents.default()
|
||||
intents.message_content = True
|
||||
client = Bot(intents=intents, command_prefix=",")
|
||||
client = Bot()
|
||||
|
||||
# Command Groups
|
||||
roles = app_commands.Group(name="roles", description="Manage role dialogues")
|
||||
|
@ -26,22 +33,7 @@ roles = app_commands.Group(name="roles", description="Manage role dialogues")
|
|||
## Group: roles
|
||||
@roles.command(name="create")
|
||||
async def roles_create_button(interaction: discord.Interaction):
|
||||
view = discord.ui.View()
|
||||
view.add_item(
|
||||
AddRoleButton(
|
||||
style=discord.ButtonStyle.primary,
|
||||
label="Add Roles",
|
||||
emoji=discord.PartialEmoji.from_str(emojize(":check_mark_button:"))
|
||||
)
|
||||
)
|
||||
view.add_item(
|
||||
RemoveRoleButton(
|
||||
style=discord.ButtonStyle.secondary,
|
||||
label="Remove Roles",
|
||||
emoji=discord.PartialEmoji.from_str(emojize(":cross_mark:"))
|
||||
)
|
||||
)
|
||||
await interaction.response.send_message(view=view)
|
||||
await interaction.response.send_message(view=RoleSelectView())
|
||||
|
||||
# Sync using ,sync ~
|
||||
@client.command()
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
from discord import Interaction, ButtonStyle, PartialEmoji
|
||||
from discord.ui import View
|
||||
from emoji import emojize
|
||||
|
||||
from src.roles import AddRoleButton, RemoveRoleButton
|
||||
|
||||
class RoleSelectView(View):
|
||||
def __init__(self):
|
||||
super().__init__(timeout=None)
|
||||
self.add_item(
|
||||
AddRoleButton(
|
||||
style=ButtonStyle.primary,
|
||||
label="Add Roles",
|
||||
emoji=PartialEmoji.from_str(emojize(":check_mark_button:")),
|
||||
custom_id="role_select:add"
|
||||
)
|
||||
)
|
||||
self.add_item(
|
||||
RemoveRoleButton(
|
||||
style=ButtonStyle.secondary,
|
||||
label="Remove Roles",
|
||||
emoji=PartialEmoji.from_str(emojize(":cross_mark:")),
|
||||
custom_id="role_select:remove"
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue