diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 9f1ab82bd..3355d134e 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -454,6 +454,28 @@ class RedBase( """ return await self.get_prefix(NotMessage(guild)) + async def set_prefixes(self, prefixes: List[str], guild: Optional[discord.Guild] = None): + """ + Set global/server prefixes. + + If ``guild`` is not provided (or None is passed), this will set the global prefixes. + + Parameters + ---------- + prefixes : List[str] + The prefixes you want to set. Passing empty list will reset prefixes for the ``guild`` + guild : Optional[discord.Guild] + The guild you want to set the prefixes for. Omit (or pass None) to set the global prefixes + + Raises + ------ + TypeError + If ``prefixes`` is not a list of strings + ValueError + If empty list is passed to ``prefixes`` when setting global prefixes + """ + await self._prefix_cache.set_prefixes(guild=guild, prefixes=prefixes) + async def get_embed_color(self, location: discord.abc.Messageable) -> discord.Color: """ Get the embed color for a location. This takes into account all related settings. diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 28e389934..fb48ea48a 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -261,7 +261,7 @@ class CoreLogic: The current (or new) list of prefixes. """ if prefixes: - await self.bot._prefix_cache.set_prefixes(guild=None, prefixes=prefixes) + await self.bot.set_prefixes(guild=None, prefixes=prefixes) return prefixes return await self.bot._prefix_cache.get_prefixes(guild=None) @@ -1284,7 +1284,7 @@ class Core(commands.Cog, CoreLogic): if not prefixes: await ctx.send_help() return - await self._prefixes(prefixes) + await ctx.bot.set_prefixes(guild=None, prefixes=prefixes) await ctx.send(_("Prefix set.")) @_set.command(aliases=["serverprefixes"]) @@ -1293,11 +1293,11 @@ class Core(commands.Cog, CoreLogic): async def serverprefix(self, ctx: commands.Context, *prefixes: str): """Sets [botname]'s server prefix(es)""" if not prefixes: - await ctx.bot._prefix_cache.set_prefixes(guild=ctx.guild, prefixes=[]) + await ctx.bot.set_prefixes(guild=ctx.guild, prefixes=[]) await ctx.send(_("Guild prefixes have been reset.")) return prefixes = sorted(prefixes, reverse=True) - await ctx.bot._prefix_cache.set_prefixes(guild=ctx.guild, prefixes=prefixes) + await ctx.bot.set_prefixes(guild=ctx.guild, prefixes=prefixes) await ctx.send(_("Prefix set.")) @_set.command()