mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-02 16:43:12 +00:00
35dfe6d9d9
style: update command usage syntax for better clarity feat: add new Roles cog for role management commands refactor(random.py, xkcd.py, run.py, ban.py, kick.py, notes.py, purge.py, slowmode.py, timeout.py, unban.py): simplify command aliases and usage instructions for better user experience feat(run.py): change command aliases to 'compile' and 'exec' to better reflect command functionality style(timeout.py): update docstring format for consistency refactor(warn.py): simplify usage instructions for better user experience feat(avatar.py): add support for optional member parameter to allow fetching avatar of other members or self style(avatar.py): update docstring format for better readability refactor(snippets.py): update usage instructions and add guild_only decorator for better command control refactor(tldr.py): add alias and usage instruction for tldr command, add guild_only decorator for better command control style(tldr.py): update docstring format for better readability refactor(wiki.py): add aliases, usage instructions to wiki commands for better user experience style(functions.py): standardize docstring format for consistency and readability
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import discord
|
|
from discord import app_commands
|
|
from discord.ext import commands
|
|
|
|
|
|
class Roles(commands.Cog):
|
|
def __init__(self, bot: commands.Bot) -> None:
|
|
self.bot = bot
|
|
|
|
role = app_commands.Group(name="roles", description="Role commands.")
|
|
|
|
@app_commands.checks.has_any_role("Admin")
|
|
@role.command(name="create", description="Creates a role in the guild.")
|
|
async def create(self, interaction: discord.Interaction, name: str) -> None:
|
|
"""
|
|
Creates a role in the guild.
|
|
|
|
Parameters
|
|
----------
|
|
interaction : discord.Interaction
|
|
The interaction object.
|
|
name : str
|
|
The name of the role to create.
|
|
"""
|
|
|
|
if interaction.guild is not None:
|
|
role = await interaction.guild.create_role(name=name)
|
|
|
|
await interaction.response.send_message(f"Created role {role.name}.")
|
|
|
|
@app_commands.checks.has_any_role("Admin")
|
|
@role.command(name="delete", description="Deletes a role in the guild.")
|
|
async def delete(self, interaction: discord.Interaction, role: discord.Role) -> None:
|
|
"""
|
|
Deletes a role in the guild.
|
|
|
|
Parameters
|
|
----------
|
|
interaction : discord.Interaction
|
|
The interaction object.
|
|
role : discord.Role
|
|
The role to delete.
|
|
"""
|
|
|
|
await role.delete()
|
|
|
|
await interaction.response.send_message(f"Deleted role {role.name}.")
|
|
|
|
|
|
async def setup(bot: commands.Bot) -> None:
|
|
await bot.add_cog(Roles(bot))
|