[Core] Add toggle for the applications.commands invite scope (#5114)

* Add toggle for applications.commands invite scope

* Add support for i18n

* Fix formatting

Co-authored-by: Kowlin <boxedpp@gmail.com>
This commit is contained in:
El Laggron 2021-06-03 17:36:28 +02:00 committed by GitHub
parent 1ee4156ac6
commit 0ce2634bb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -118,6 +118,7 @@ class RedBase(
description="Red V3", description="Red V3",
invite_public=False, invite_public=False,
invite_perm=0, invite_perm=0,
invite_commands_scope=False,
disabled_commands=[], disabled_commands=[],
disabled_command_msg="That command is disabled.", disabled_command_msg="That command is disabled.",
extra_owner_destinations=[], extra_owner_destinations=[],

View File

@ -377,9 +377,12 @@ class CoreLogic:
Invite URL. Invite URL.
""" """
app_info = await self.bot.application_info() app_info = await self.bot.application_info()
perms_int = await self.bot._config.invite_perm() data = await self.bot._config.all()
commands_scope = data["invite_commands_scope"]
scopes = ("bot", "applications.commands") if commands_scope else None
perms_int = data["invite_perm"]
permissions = discord.Permissions(perms_int) permissions = discord.Permissions(perms_int)
return discord.utils.oauth_url(app_info.id, permissions) return discord.utils.oauth_url(app_info.id, permissions, scopes=scopes)
@staticmethod @staticmethod
async def _can_get_invite_url(ctx): async def _can_get_invite_url(ctx):
@ -1565,6 +1568,26 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
await self.bot._config.invite_perm.set(level) await self.bot._config.invite_perm.set(level)
await ctx.send("The new permissions level has been set.") await ctx.send("The new permissions level has been set.")
@inviteset.command()
async def commandscope(self, ctx: commands.Context):
"""
Add the `applications.commands` scope to your invite URL.
This allows the usage of slash commands on the servers that invited your bot with that scope.
Note that previous servers that invited the bot without the scope cannot have slash commands, they will have to invite the bot a second time.
"""
enabled = not await self.bot._config.invite_commands_scope()
await self.bot._config.invite_commands_scope.set(enabled)
if enabled is True:
await ctx.send(
_("The `applications.commands` scope has been added to the invite URL.")
)
else:
await ctx.send(
_("The `applications.commands` scope has been removed from the invite URL.")
)
@commands.command() @commands.command()
@checks.is_owner() @checks.is_owner()
async def leave(self, ctx: commands.Context, *servers: GuildConverter): async def leave(self, ctx: commands.Context, *servers: GuildConverter):