Create register group and highscore slash subcommand.
This commit is contained in:
@@ -2,20 +2,69 @@
|
||||
Bot command for registering various channels to the bot.
|
||||
"""
|
||||
|
||||
from nextcord import Embed
|
||||
from typing import Optional
|
||||
|
||||
from nextcord import Embed, Interaction, Permissions, SlashOption
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
|
||||
|
||||
class RegisterVerificationChannel(commands.Cog, name="Register"):
|
||||
"""Bot command for registering various channels to the bot."""
|
||||
class Register(commands.Cog, name="Register"):
|
||||
"""
|
||||
Class holds various register commands.
|
||||
|
||||
Args:
|
||||
commands.Cog: Parent class
|
||||
name (str, optional): Name of Cog. Defaults to "Register".
|
||||
"""
|
||||
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=Permissions(administrator=True))
|
||||
async def register(self):
|
||||
"""
|
||||
Parent slash command, never called.
|
||||
"""
|
||||
|
||||
@register.subcommand(description="highscore")
|
||||
async def highscore(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
channel: nextcord.abc.GuildChannel = SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
_summary_
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): _description_
|
||||
channel (nextcord.abc.GuildChannel, optional): _description_.
|
||||
|
||||
Defaults to SlashOption( description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
).
|
||||
"""
|
||||
if not channel:
|
||||
channel = interaction.channel
|
||||
channel_id = channel.id
|
||||
guild = highscores_data.get_guild(interaction.guild_id)
|
||||
await interaction.send(
|
||||
f"Registered <#{channel_id}> as channel to post highscores in.", ephemeral=True
|
||||
)
|
||||
guild.highscore_channel = channel_id
|
||||
highscores_data.save_guild_data(guild)
|
||||
|
||||
@commands.command(name="register")
|
||||
@commands.has_permissions(administrator=True)
|
||||
# @commands.has_permissions(administrator=True)
|
||||
async def register_highscores(self, ctx: commands.Context, registration_type: str) -> None:
|
||||
"""A command which registers current channel as for various uses.
|
||||
Usage:
|
||||
@@ -66,4 +115,4 @@ class RegisterVerificationChannel(commands.Cog, name="Register"):
|
||||
# It is necessary to add these functions to the bot.
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
"""Adds function to bot"""
|
||||
bot.add_cog(RegisterVerificationChannel(bot))
|
||||
bot.add_cog(Register(bot))
|
||||
|
||||
Reference in New Issue
Block a user