Add slash command support for all cogs

This commit is contained in:
pacnpal
2024-11-14 21:43:01 +00:00
parent 73f142addd
commit 2622db6d3c
5 changed files with 203 additions and 64 deletions

View File

@@ -1,6 +1,6 @@
# Birthday Cog for Red-DiscordBot
This cog allows you to assign a special role to users on their birthday and send them a celebratory message with cake (or pie) emojis!
This cog allows you to assign a special role to users on their birthday and send them a celebratory message with cake (or pie) emojis! Supports both traditional prefix commands and slash commands.
## Installation
@@ -29,13 +29,17 @@ Replace `[p]` with your bot's prefix.
## Setup
Before using the cog, you need to set it up:
Before using the cog, you need to set it up. You can use either prefix commands or slash commands:
1. Set the birthday role:
```
[p]birthdayset role @Birthday
```
or
```
/birthdayset role @Birthday
```
**Note:** The bot's role must be above the birthday role in the server's role hierarchy, but users assigning the birthday role do not need to have a role above it.
@@ -44,18 +48,30 @@ Before using the cog, you need to set it up:
```
[p]birthdayset addrole @Moderator
```
or
```
/birthdayset addrole @Moderator
```
3. (Optional) Set the timezone for role expiration:
```
[p]birthdayset timezone America/New_York
```
or
```
/birthdayset timezone America/New_York
```
4. (Optional) Set a specific channel for birthday announcements:
```
[p]birthdayset channel #birthdays
```
or
```
/birthdayset channel #birthdays
```
If not set, the birthday message will be sent in the channel where the command is used.
@@ -66,6 +82,10 @@ To assign the birthday role to a user:
```
[p]birthday @User
```
or
```
/birthday @User
```
This will assign the birthday role to the user and send a celebratory message with random cake (or pie) emojis. The role will be automatically removed at midnight in the specified timezone.
@@ -78,15 +98,19 @@ This will assign the birthday role to the user and send a celebratory message wi
- Option to set a specific channel for birthday announcements (defaults to the channel where the command is used)
- Restricts usage of the birthday command to specified roles
- Users can assign the birthday role without needing a role higher than it in the hierarchy
- Full slash command support for all commands
## Commands
- `[p]birthdayset role`: Set the birthday role
- `[p]birthdayset addrole`: Add a role that can use the birthday command
- `[p]birthdayset removerole`: Remove a role from using the birthday command
- `[p]birthdayset timezone`: Set the timezone for the birthday role expiration
- `[p]birthdayset channel`: Set the channel for birthday announcements
- `[p]birthday`: Assign the birthday role to a user
All commands support both prefix and slash command syntax:
- `[p]birthdayset role` or `/birthdayset role`: Set the birthday role
- `[p]birthdayset addrole` or `/birthdayset addrole`: Add a role that can use the birthday command
- `[p]birthdayset removerole` or `/birthdayset removerole`: Remove a role from using the birthday command
- `[p]birthdayset timezone` or `/birthdayset timezone`: Set the timezone for the birthday role expiration
- `[p]birthdayset channel` or `/birthdayset channel`: Set the channel for birthday announcements
- `[p]birthday` or `/birthday`: Assign the birthday role to a user
- `[p]bdaycheck` or `/bdaycheck`: Check upcoming birthday role removal tasks
## Support

View File

@@ -22,11 +22,12 @@ class Birthday(commands.Cog):
self.config.register_guild(**default_guild)
self.birthday_tasks = {}
@commands.group()
@commands.hybrid_group()
@checks.admin_or_permissions(manage_roles=True)
async def birthdayset(self, ctx):
"""Birthday cog settings."""
pass
if ctx.invoked_subcommand is None:
await ctx.send_help()
@birthdayset.command()
@checks.is_owner()
@@ -69,7 +70,7 @@ class Birthday(commands.Cog):
allowed_roles.remove(role.id)
await ctx.send(f"Removed {role.name} from the list of roles that can use the birthday command.")
@commands.command()
@commands.hybrid_command()
async def birthday(self, ctx, member: discord.Member):
"""Assign the birthday role to a user until midnight in the set timezone."""
# Check if the user has permission to use this command
@@ -79,7 +80,7 @@ class Birthday(commands.Cog):
birthday_role_id = await self.config.guild(ctx.guild).birthday_role()
if not birthday_role_id:
return await ctx.send("The birthday role hasn't been set. An admin needs to set it using `[p]birthdayset role`.")
return await ctx.send("The birthday role hasn't been set. An admin needs to set it using `/birthdayset role`.")
birthday_role = ctx.guild.get_role(birthday_role_id)
if not birthday_role:
@@ -122,7 +123,7 @@ class Birthday(commands.Cog):
await self.schedule_birthday_role_removal(ctx.guild, member, birthday_role, midnight)
@commands.command()
@commands.hybrid_command()
async def bdaycheck(self, ctx):
"""Check the upcoming birthday role removal tasks."""
# Check if the user has permission to use this command