Ejemplo n.º 1
0
    async def delete(self, ctx: commands.Context,
                     destination: typing.Union[discord.User, discord.Member,
                                               discord.TextChannel,
                                               discord.DMChannel],
                     message_id: int):
        """Delete the specified message sent by the bot"""
        target = destination.dm_channel if isinstance(
            destination, (discord.User, discord.Member)) else destination
        target = await target.fetch_message(message_id)

        if not target:
            return ctx.reply("Can not find the specified message")
        if target.author.id != self.bot.user.id:
            return ctx.reply(
                "That message is not sent by the bot, therefore can't be deleted"
            )

        try:
            await target.delete()
        except (discord.HTTPException, discord.NotFound):
            return ctx.reply(
                "Unknown error has occurred, likely the message is too old to be deleted"
            )
        await ctx.message.add_reaction(emoji="🗑️")
Ejemplo n.º 2
0
    async def no_slash(self, ctx: commands.Context):
        """Attempt to remove permission to use slash commands from all roles of the server,
        1 hour cooldown after use."""
        if ctx.guild.id in self.api_limit:
            return ctx.reply("API call cooldown, please try again later")
        else:
            self.api_limit.append(ctx.guild.id)

        roles = self.slash_perm_check(ctx.guild.roles)
        hoist = highest_role_position(ctx.me.roles)

        msg = await ctx.reply(f"0 / {len(roles)} roles modified")

        success = []
        no_perm = []
        failed = []
        for i in range(len(roles)):
            perm = roles[i].permissions
            perm.use_slash_commands = False
            if roles[i].position < hoist:
                try:
                    await roles[i].edit(
                        permissions=perm,
                        reason=
                        f"Remove use slash command perm by {ctx.message.author}"
                    )
                    success.append(roles[i])
                except discord.HTTPException:
                    failed.append(roles[i])
            else:
                no_perm.append(roles[i])
            if i != 0 and i % 10 == 0:
                await msg.edit(content=f"{i} / {len(roles)} roles modified...")

        await msg.delete()

        sends = []
        embed_format = discord.Embed(colour=0x1abc9c,
                                     title="Successfully modified roles",
                                     description="None...",
                                     timestamp=ctx.message.created_at)

        def appending_result(arr: list):
            if len(arr) > 0:
                page = 0
                string = ""
                for a in range(len(arr)):
                    string += f"{arr[a].mention}\n"
                    if (a % 25 == 0 and a != 0) or len(arr) - 1 == a:
                        sends.append(embed_format.copy())
                        sends[len(sends) - 1].description = string
                        string = ""
                        page += 1
                        sends[
                            len(sends) -
                            1].title = f"{sends[len(sends) - 1].title} {page}"

        appending_result(success)
        embed_format.title = "Not enough permission to modify the following roles"
        embed_format.colour = 0xf1c40f
        appending_result(no_perm)
        embed_format.title = "Failed to modify the following roles"
        embed_format.colour = 0xe74c3c
        appending_result(failed)
        for i in sends:
            await ctx.reply(embed=i)

        await asyncio.sleep(3600)
        self.api_limit.remove(ctx.guild.id)