[3.4] [Admin] Add [p]selfroleset clear command (#5387) (#5409)

(cherry picked from commit b64ece3ee9)

Co-authored-by: Kreus Amredes <67752638+Kreusada@users.noreply.github.com>

Co-authored-by: Kreus Amredes <67752638+Kreusada@users.noreply.github.com>
This commit is contained in:
Red-GitHubBot
2021-10-19 12:28:10 +02:00
committed by GitHub
parent 3cf0d5ebe9
commit 59c92041fc
2 changed files with 52 additions and 1 deletions

View File

@@ -160,6 +160,22 @@ Add a role, or a selection of roles, to the list of available selfroles.
* ``<role>``: The role to add to the list. |role-input|
.. _admin-command-selfroleset-clear:
"""""""""""""""""
selfroleset clear
"""""""""""""""""
**Syntax**
.. code-block:: none
[p]selfroleset clear
**Description**
Clear the list of available selfroles for this server.
.. _admin-command-selfroleset-remove:
""""""""""""""""""

View File

@@ -3,10 +3,11 @@ import logging
from typing import Tuple
import discord
from redbot.core import Config, checks, commands
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import box
from redbot.core.utils.predicates import MessagePredicate
from .announcer import Announcer
from .converters import SelfRole
@@ -509,6 +510,40 @@ class Admin(commands.Cog):
await ctx.send(message)
@selfroleset.command(name="clear")
async def selfroleset_clear(self, ctx: commands.Context):
"""Clear the list of available selfroles for this server."""
current_selfroles = await self.config.guild(ctx.guild).selfroles()
if not current_selfroles:
return await ctx.send(_("There are currently no selfroles."))
await ctx.send(
_("Are you sure you want to clear this server's selfrole list?") + " (yes/no)"
)
try:
pred = MessagePredicate.yes_or_no(ctx, user=ctx.author)
await ctx.bot.wait_for("message", check=pred, timeout=60)
except asyncio.TimeoutError:
await ctx.send(_("You took too long to respond."))
return
if pred.result:
for role in current_selfroles:
role = ctx.guild.get_role(role)
if role is None:
continue
if not self.pass_user_hierarchy_check(ctx, role):
await ctx.send(
_(
"I cannot clear the selfroles because the selfrole '{role.name}' is higher than or equal to your highest role in the Discord hierarchy."
).format(role=role)
)
return
await self.config.guild(ctx.guild).selfroles.clear()
await ctx.send(_("Selfrole list cleared."))
else:
await ctx.send(_("No changes have been made."))
@commands.command()
@checks.is_owner()
async def serverlock(self, ctx: commands.Context):