python类PermissionOverwrite()的实例源码

YotsugiMain.py 文件源码 项目:YotsugiBot 作者: Kyousei 项目源码 文件源码 阅读 13 收藏 0 点赞 0 评论 0
def unmute(ctx, *, member : discord.Member):
    if not ctx.message.author.server_permissions.mute_members:
        return print(Fore.RED + "Command Failed To Execute |\n       Command Ran In:[" + ctx.message.server.id + "]\n       User:[" + ctx.message.author.id + "]\n       Channel:[" + ctx.message.channel.id + "]\n       Reason: " + Fore.YELLOW + "Insufficient Permissions! Both user and bot need Mute Members permission!")
    overwrite = discord.PermissionOverwrite()
    overwrite.send_messages = True
    await client.edit_channel_permissions(ctx.message.channel, member, overwrite)
    await client.say("**%s** has been unmuted!"%member.mention)
    print(Fore.CYAN + "Command Successfully Executed |\n       Command Ran In:[" + ctx.message.server.id + "]\n       User:[" + ctx.message.author.id + "]\n       Channel:[" + ctx.message.channel.id + "]")
mod.py 文件源码 项目:Discord-Selfbot 作者: appu1232 项目源码 文件源码 阅读 85 收藏 0 点赞 0 评论 0
def are_overwrites_empty(self, overwrites):
        """There is currently no cleaner way to check if a
        PermissionOverwrite object is empty"""
        original = [p for p in iter(overwrites)]
        empty = [p for p in iter(discord.PermissionOverwrite())]
        return original == empty
punish.py 文件源码 项目:refactored-cogs 作者: Kowlin 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def new_channel(self, c):
        if 'Punished' in [r.name for r in c.server.roles]:
            if c.type.name == 'text':
                perms = discord.PermissionOverwrite()
                perms.send_messages = False
                r = discord.utils.get(c.server.roles, name='Punished')
                await self.bot.edit_channel_permissions(c, r, perms)
                log.debug('Punished role created on channel: {}'.format(c.id))
bot.py 文件源码 项目:discord-raid-coordinator 作者: dandesousa 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def start_raid_group(user, message, description):
    """Starts a new raid group."""
    global should_refresh_active_raids

    # get the server, use the message because user might be a webhook with no server
    server = message.server

    # find an available raid channel
    channel = get_available_raid_channel(server)

    if channel:
        # lock the channel
        locked_channels.add(channel)

        # purge all messages
        await client.purge_from(channel)

        try:
            # set the topic
            await client.edit_channel(channel, topic=encode_message(user, message))

            # create a role with the same name as this channel
            role = await client.create_role(server, name=channel.name, mentionable=True)

            # calculate expiration time
            expiration_dt = adjusted_datetime(get_raid_expiration(message.timestamp))
            summary_message = await client.send_message(channel, embed=get_raid_summary_embed(user, channel.name, expiration_dt, description))

            # add shortcut reactions for commands
            await client.add_reaction(summary_message, get_leave_emoji())

            # set channel permissions to make raid viewers see the raid.
            perms = discord.PermissionOverwrite(read_messages=True)
            role = await get_raid_viewer_role(server)
            if role is not None:
                await client.edit_channel_permissions(channel, role, perms)

        finally:
            # unlock the channel
            locked_channels.remove(channel)

            # refresh active raids in future
            should_refresh_active_raids = True

        return channel
stars.py 文件源码 项目:LunaBot 作者: miraai 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def moonboard(self, ctx, *, name: str = 'moonboard'):
        """Sets up the starboard for this server.

        This creates a new channel with the specified name
        and makes it into the server's "starboard". If no
        name is passed in then it defaults to "starboard".
        If the channel is deleted then the starboard is
        deleted as well.

        You must have Administrator permissions to use this
        command or the Bot Admin role.
        """

        server = ctx.message.server

        stars = self.stars.get(server.id, {})
        old_starboard = self.bot.get_channel(stars.get('channel'))
        if old_starboard is not None:
            fmt = 'This channel already has a moonboard ({.mention})'
            await self.bot.say(fmt.format(old_starboard))
            return

        # an old channel might have been deleted and thus we should clear all its star data
        stars = {}

        my_permissions = ctx.message.channel.permissions_for(server.me)
        args = [server, name]

        if my_permissions.manage_roles:
            mine = discord.PermissionOverwrite(read_messages=True, send_messages=True)
            everyone = discord.PermissionOverwrite(send_messages=False, embed_links=False)
            args.append((server.me, mine))
            args.append((server.default_role, everyone))

        try:
            channel = await self.bot.create_channel(*args)
        except discord.Forbidden:
            await self.bot.say('**Error!** I do not have permissions to create a channel.')
        except discord.HTTPException:
            await self.bot.say('**Error!** This channel name is bad or an unknown error happened.')
        else:
            stars['channel'] = channel.id
            await self.stars.put(server.id, stars)
            await self.bot.say('**Done!** Moonboard created at ' + channel.mention)
stars.py 文件源码 项目:jose 作者: lnmds 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def starboard(self, ctx, channel_name: str):
        """Create a starboard channel.

        If the name specifies a NSFW channel, the starboard gets marked as NSFW.

        NSFW starboards allow messages from NSFW channels to be starred without any censoring.
        If your starboard gets marked as a SFW starboard, messages from NSFW channels get completly ignored.
        """

        guild = ctx.guild
        config = await self.get_starconfig(guild.id)
        if config is not None:
            await ctx.send("You already have a starboard. If you want"
                           " to detach josé from it, use the "
                           "`stardetach` command")
            return

        po = discord.PermissionOverwrite
        overwrites = {
                guild.default_role: po(read_messages=True, send_messages=False),
                guild.me: po(read_messages=True, send_messages=True),
        }

        try:
            starboard_chan = await guild.create_text_channel(
                channel_name,
                overwrites=overwrites,
                reason='Created starboard channel')

        except discord.Forbidden:
            return await ctx.send('No permissions to make a channel.')
        except discord.HTTPException as err:
            log.exception('Got HTTP error from starboard create')
            return await ctx.send(f'**SHIT!!!!**:  {err!r}')

        log.info(f'[starboard] Init starboard @ {guild.name}[{guild.id}]')

        # create config here
        config = empty_starconfig(guild)
        config['starboard_id'] = starboard_chan.id

        res = await self.starconfig_coll.insert_one(config)
        if not res.acknowledged:
            raise self.SayException('Failed to create starboard config (no ack)')

        await ctx.send('All done, I guess!')
stars.py 文件源码 项目:epicord-bot 作者: Epicord 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def starboard(self, ctx, *, name: str = 'starboard'):
        """Sets up the starboard for this server.

        This creates a new channel with the specified name
        and makes it into the server's "starboard". If no
        name is passed in then it defaults to "starboard".
        If the channel is deleted then the starboard is
        deleted as well.

        You must have Administrator permissions to use this
        command or the Bot Admin role.
        """

        server = ctx.message.server

        stars = self.stars.get(server.id, {})
        old_starboard = self.bot.get_channel(stars.get('channel'))
        if old_starboard is not None:
            fmt = 'This server already has a starboard ({.mention})'
            await self.bot.say(fmt.format(old_starboard))
            return

        # an old channel might have been deleted and thus we should clear all its star data
        stars = {}

        my_permissions = ctx.message.channel.permissions_for(server.me)
        args = [server, name]

        if my_permissions.manage_roles:
            mine = discord.PermissionOverwrite(send_messages=True, manage_messages=True, embed_links=True)
            everyone = discord.PermissionOverwrite(read_messages=True, send_messages=False, read_message_history=True)
            args.append((server.me, mine))
            args.append((server.default_role, everyone))

        try:
            channel = await self.bot.create_channel(*args)
        except discord.Forbidden:
            await self.bot.say('\N{NO ENTRY SIGN} I do not have permissions to create a channel.')
        except discord.HTTPException:
            await self.bot.say('\N{PISTOL} This channel name is bad or an unknown error happened.')
        else:
            stars['channel'] = channel.id
            await self.stars.put(server.id, stars)
            await self.bot.say('\N{GLOWING STAR} Starboard created at ' + channel.mention)
stars.py 文件源码 项目:PyMiki 作者: TheGrammarJew 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def starboard(self, ctx, *, name='starboard'):
        """Sets up the starboard for this server.

        This creates a new channel with the specified name
        and makes it into the server's "starboard". If no
        name is passed in then it defaults to "starboard".

        You must have Manage Server permission to use this.
        """

        # bypass the cache just in case someone used the star
        # reaction earlier before having it set up, or they
        # decided to use the ?star command
        self.get_starboard.invalidate(self, ctx.guild.id)

        starboard = await self.get_starboard(ctx.guild.id, connection=ctx.db)
        if starboard.channel is not None:
            return await ctx.send(f'This server already has a starboard ({starboard.channel.mention}).')

        perms = ctx.channel.permissions_for(ctx.me)

        if not perms.manage_roles or not perms.manage_channels:
            return await ctx.send('\N{NO ENTRY SIGN} I do not have proper permissions (Manage Roles and Manage Channel)')

        overwrites = {
            ctx.me: discord.PermissionOverwrite(read_messages=True, send_messages=True, manage_messages=True,
                                                embed_links=True, read_message_history=True),
            ctx.guild.default_role: discord.PermissionOverwrite(read_messages=True, send_messages=False,
                                                                read_message_history=True)
        }

        reason = f'{ctx.author} (ID: {ctx.author.id}) has created the starboard channel.'

        try:
            channel = await ctx.guild.create_text_channel(name=name, overwrites=overwrites, reason=reason)
        except discord.Forbidden:
            return await ctx.send('\N{NO ENTRY SIGN} I do not have permissions to create a channel.')
        except discord.HTTPException:
            return await ctx.send('\N{NO ENTRY SIGN} This channel name is bad or an unknown error happened.')

        query = "INSERT INTO starboard (id, channel_id) VALUES ($1, $2);"
        try:
            await ctx.db.execute(query, ctx.guild.id, channel.id)
        except:
            await channel.delete(reason='Failure to commit to create the ')
            await ctx.send('Could not create the channel due to an internal error. Join the bot support server for help.')
        else:
            self.get_starboard.invalidate(self, ctx.guild.id)
            await ctx.send(f'\N{GLOWING STAR} Starboard created at {channel.mention}.')


问题


面经


文章

微信
公众号

扫码关注公众号