#!/bin/env python3 from typing import Literal, Optional from emoji import emojize from yaml import safe_load import discord from discord.ext import commands from discord.ext.commands import Greedy, Context from discord import app_commands from src.roles import AddRoleButton, RemoveRoleButton class Bot(commands.Bot): 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=",") # Command Groups roles = app_commands.Group(name="roles", description="Manage role dialogues") # Commands ## 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) # Sync using ,sync ~ @client.command() @commands.guild_only() @commands.is_owner() async def sync( ctx: Context, guilds: Greedy[discord.Object], spec: Optional[Literal["~", "*", "^"]] = None) -> None: if not guilds: if spec == "~": synced = await ctx.bot.tree.sync(guild=ctx.guild) elif spec == "*": ctx.bot.tree.copy_global_to(guild=ctx.guild) synced = await ctx.bot.tree.sync(guild=ctx.guild) elif spec == "^": ctx.bot.tree.clear_commands(guild=ctx.guild) await ctx.bot.tree.sync(guild=ctx.guild) synced = [] else: synced = await ctx.bot.tree.sync() await ctx.send( f"Synced {len(synced)} commands {'globally' if spec is None else 'to the current guild.'}" ) return ret = 0 for guild in guilds: try: await ctx.bot.tree.sync(guild=guild) except discord.HTTPException: pass else: ret += 1 await ctx.send(f"Synced the tree to {ret}/{len(guilds)}.") if __name__ == "__main__": client.tree.add_command(roles) client.run(client.config['auth']['token'])